<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Plotly &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/plotly/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 14 May 2014 18:00:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>Plotly graphs in IPython Notebook</title>
		<link>https://undocumentedmatlab.com/articles/plotly-graphs-in-ipython-notebook?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=plotly-graphs-in-ipython-notebook</link>
					<comments>https://undocumentedmatlab.com/articles/plotly-graphs-in-ipython-notebook#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 14 May 2014 18:00:22 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Commercial]]></category>
		<category><![CDATA[Plotly]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4797</guid>

					<description><![CDATA[<p>Plotly graphs can be embedded in an IPython Notebook directly from Matlab. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/plotly-graphs-in-ipython-notebook">Plotly graphs in IPython Notebook</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/plotly-graphs" rel="bookmark" title="Plotly graphs">Plotly graphs </a> <small>Plotly charts can be created and customized in Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jfreechart-graphs-and-gauges" rel="bookmark" title="JFreeChart graphs and gauges">JFreeChart graphs and gauges </a> <small>JFreeChart is an open-source charting library that can easily be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/pinning-annotations-to-graphs" rel="bookmark" title="Pinning annotations to graphs">Pinning annotations to graphs </a> <small>Annotation object can be programmatically set at, and pinned-to, plot axes data points. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-axes-part-5-origin-crossover-and-labels" rel="bookmark" title="Customizing axes part 5 &#8211; origin crossover and labels">Customizing axes part 5 &#8211; origin crossover and labels </a> <small>The axes rulers (axles) can be made to cross-over at any x,y location within the chart. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>Last December, I hosted an article on <a target="_blank" rel="nofollow" href="http://plot.ly">plot.ly</a>&#8216;s awesome online plotting interface for Matlab. Today, I wish to welcome Andrey Dimitrov, a plot.ly engineer, who will discuss generating Plotly graphs in IPython Notebooks, all from within Matlab. The Plotly idea, of generating online interactive graphs, is radically different from Matlab&#8217;s standard static plots and deserves a second look. Note that Plotly is a commercial venture.</i></p>
<h3 id="overview">Overview</h3>
<p>The <a target="_blank" rel="nofollow" href="https://plot.ly/api/MATLAB">Plotly Matlab API</a> enables leveraging the power of Plotly graphs conveniently from your Matlab environment, meaning that you can make a graph like this in Matlab:<br />
<center><iframe id="igraph" src="https://plot.ly/~Matlab-demos/3/400/320/" width="400" height="320" seamless="seamless" scrolling="no"></iframe></center><br />
You can work in Matlab, share your graphs and data, and then edit it together online. It&#8217;s all backed up, collaborative, and can be edited with other APIs and the GUI. It&#8217;s free, embeddable, and keeps data and graphs together.<br />
The API provides a set of functions that structure your data and send it to Plotly. All editing can be done through the API or the online GUI. In addition, the <b><i>Plotly</i></b> wrapper function can take away all the hassle of learning a new graphing syntax. Just build your figures in Matlab as usual and send them to Plotly with one call to the wrapper.<br />
This notebook goes through some usage scenarios to get Matlab users started with the tool. A version of this post (with several more examples) was also written as an <a target="_blank" rel="nofollow" href="http://nbviewer.ipython.org/github/plotly/IPython-plotly/blob/master/See more/MATLAB_Wrapper_Examples.ipynb">IPython Notebook</a>. Some steps are specific to making everything work in an IPython notebook, but you can always skip through those and get to the good stuff.<br />
<span id="more-4797"></span></p>
<h3 id="example1">A simple example</h3>
<p>First, we need to start a Matlab server. In the IPython Notebook:</p>
<pre lang='python'>
In [1]:
import pymatbridge as pymat
ip = get_ipython()
pymat.load_ipython_extension(ip, matlab='C:\Users\Andrey\matlab_shortcut.lnk')
</pre>
<p>This starts Matlab on the local computer and we can now enter Matlab commands in our IPython Notebook:</p>
<pre>
Starting Matlab on http://localhost:60199
 visit http://localhost:60199/exit.m to shut down same
...Matlab started and connected!
</pre>
<p>Note to Windows users: Python doesn&#8217;t like file paths with spaces! Above, a shortcut to matlab.exe was created and placed it in a path that did not contain spaces. It&#8217;s a bit of a hack, there are better ways to do it I&#8217;m sure.<br />
Now we are ready to run Matlab. Let&#8217;s set up the Plotly environment next. This needs to be done only once per session. The next few lines import the Plotly Matlab API and sign in to your account. For these examples we are using the Matlab-demos account. You can <a target="_blank" rel="nofollow" href="https://plot.ly/ssi/">sign up at Plotly</a> to get a username and key (<a target="_blank" rel="nofollow" href="https://plot.ly/api/MATLAB/getting-started/authentication">more info</a>), or just use the Matlab-demos username and key below to make these examples work. In Matlab:</p>
<pre lang='matlab'>
In [2]:
%%matlab
api_path = 'C:\Users\Andrey\Dropbox\ANDREY\PLOTLY\Matlab-api\plotly';
addpath(genpath(api_path))
signin('Matlab-demos', '3qhoowzv5n');  % account username & key
</pre>
<p>We are now signed in and can convert and publish the Matlab figures in Plotly. The Plotly Matlab API helps generate data and layout data structures that contain all the information needed to make a plot. The <i><b>plotly</b></i> command sends these to the server and the result is displayed via the response variable. In it, a URL points to the generated plot online. In this notebook, we focus of the Plotly wrapper. The <i><b>fig2plotly</b></i> command at the end of the code will convert the current figure into a format that Plotly understands and publish it.<br />
Let&#8217;s make a simple plot in Matlab and publish it to Plotly:</p>
<pre lang='matlab'>
In [3]:
% some random points
my_random_data = rand(20,4);
% a 2D scatter plot with size and color inputs
figure
scatter(my_random_data(:,1), my_random_data(:,2), 100*my_random_data(:,3), my_random_data(:,4), 'filled')
% Convert the static figure into an online Plotly chart
response = fig2plotly();
High five! You successfully sent some data to your account on Plotly. View your plot in your browser at https://plot.ly/~Matlab-demos/0 or inside your plot.ly account where it is named 'untitled'.
</pre>
<p>The plot has been sent to the Matlab-demos account and the command returns the unique URL <a target="_blank" rel="nofollow" href="https://plot.ly/~Matlab-demos/0">https://plot.ly/~Matlab-demos/0</a> where anyone can view the rendered graph. By default, the plot is named &#8220;untitled&#8221;. In the following examples, we see how the command allows the user to give a custom name, otherwise it will try to extract it from the figure title.<br />
Every plotly graph URL can be <a target="_blank" rel="nofollow" href="https://plot.ly/api/MATLAB/docs/iframes">embedded in HTML as wrapped in an IFrame</a>. In fact, the Plotly figure above can be embedded in an HTML (as in this webpage) using the following HTML code:</p>
<pre lang='html'><iframe src="https://plot.ly/~Matlab-demos/0/400/320/" width="400" height="320" seamless="seamless" scrolling="no"></iframe></pre>
<p><center><iframe id="igraph" src="https://plot.ly/~Matlab-demos/0/400/320/" width="400" height="320" seamless="seamless" scrolling="no"></iframe></center><br />
Here&#8217;s a quick Python utility function that will embed a plotly graph in IPython Notebooks:</p>
<pre lang='python'>
In [4]:
from IPython.display import HTML
def show_plot(url, width=700, height=500):
    s = '<iframe loading="lazy" height="%s" id="igraph" scrolling="no" seamless="seamless" src="%s" width="%s"></iframe>' %\
    (height+50, "/".join(map(str,[url, width, height])), width+50)
    return HTML(s)
</pre>
<p>To see the resulting plot, we only need to input the following command:</p>
<pre lang='python'>
In [5]:
show_plot('https://plot.ly/~Matlab-demos/0')
</pre>
<p>(resulting in a display of the interactive chart above)</p>
<h3 id="example2">Example 2: Convex Hull</h3>
<p>Note: The original example data can be found at the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/discovery/gallery.html">Matlab Plot Gallery</a>.</p>
<pre lang='matlab'>
In [6]:
%%matlab
% This is an example of how to add text to a plot in Matlab.
% Read about the <http://www.mathworks.com/help/matlab/ref/text.html |text|> function in the Matlab documentation.
% Go to <http://www.mathworks.com/discovery/gallery.html Matlab Plot Gallery>
% Load the points for creating a spline curve
load('C:\Users\Andrey\Dropbox\ANDREY\PLOTLY\Matlab_Examples\Add_Text_to_Plot_1\splineData');
% Plot the points for the spline curve
figure;
plot(points(:,1), points(:,2), ':ok');
hold on;
% Plot the spline curve
plot(x, y, 'LineWidth', 2);
axis([0.5 7 -0.8 1.8]);
% Add a title and axis labels
title('The Convex-Hull Property');
xlabel('x');
ylabel('y');
% Label points 3, 4, & 5 of the spline curve
xt = points(3,1) - 0.05;
yt = points(3,2) - 0.10;
text(xt, yt, 'Point 3', 'FontSize',12);
xt = points(4,1) - 0.05;
yt = points(4,2) + 0.10;
text(xt, yt, 'Point 4', 'FontSize',12);
xt = points(5,1) + 0.15;
yt = points(5,2) - 0.05;
text(6.1,.5, 'Point 5', 'FontSize',12);
% Convert the static figure into an online Plotly chart
response = fig2plotly();
</pre>
<p>This time, the plot was named &#8220;The Convex Hull Property&#8221;. Back in the IPython Notebook:</p>
<pre lang='python'>
In [7]:
show_plot('https://plot.ly/~Matlab-demos/1')
Out [7]:
</pre>
<p><center><iframe loading="lazy" id="igraph" src="https://plot.ly/~Matlab-demos/1/400/300/" width="400" height="300" seamless="seamless" scrolling="no"></iframe></center><br />
Sweet! Let&#8217;s keep going&#8230;<br />
We will reuse the same code and add some more inputs to the <i><b>fig2plotly</b></i> command. We can specify explicitly the figure object that will be published (it doesn&#8217;t need to be the current one). In addition, we add &#8216;open&#8217; to turn off the automatic opening of a browser window with the response URL, and we &#8216;strip&#8217; the plot of all Matlab styling and revert to Plotly defaults. This allows users to use Plotly&#8217;s styling capabilities from the API of at the online UI.<br />
The Matlab code is as above, except for the last (<i><b>fig2plotly</b></i>) line:</p>
<pre lang='matlab'>
% Convert the static figure into an online Plotly chart
hFig = gcf;  % any figure, for now we use the current
response = fig2plotly(hFig, 'strip',true, 'open',false, 'name','Stripped plot');
</pre>
<pre lang='python'>
In [8]:
show_plot('https://plot.ly/~Matlab-demos/2')
Out [8]:
</pre>
<p><center><iframe loading="lazy" id="igraph" src="https://plot.ly/~Matlab-demos/2/400/320/" width="400" height="320" seamless="seamless" scrolling="no"></iframe></center></p>
<h3 id="example3">Example 3: Multiple Plots</h3>
<pre lang='matlab'>
In [9]:
%%matlab
% Create data
t = linspace(0,2*pi);
t(1) = eps;
y = sin(t);
% Place axes at (0.1,0.1) with width and height of 0.8
figure;
handaxes1 = axes('position', [0.1 0.1 0.8 0.8]);
% Main plot
plot(t, y);
xlabel('t');
ylabel('sin(t)');
set(handaxes1, 'box', 'off');
% Adjust X/Y label font
set(get(gca, 'xlabel'), 'fontsize',16, 'fontweight','bold');
set(get(gca, 'ylabel'), 'fontsize',16, 'fontweight','bold');
% Place second set of axes on same plot
handaxes2 = axes('position', [0.6 0.6 0.2 0.2]);
fill(t, y.^2, 'g');
set(handaxes2, 'box', 'off');
xlabel('t');
ylabel('(sin(t))^2');
% Adjust X/Y label font
set(get(handaxes2,'xlabel'), 'fontname','times')
set(get(handaxes2,'ylabel'), 'fontname','times')
% Add another set of axes
handaxes3 = axes('position', [0.25 0.25 0.2 0.2]);
plot(t, y.^3);
set(handaxes3, 'box','off');
xlabel('t');
ylabel('(sin(t))^3');
% Convert the static figure into an online Plotly chart
response = fig2plotly(gcf, 'name','Multiple_Plots');
</pre>
<pre lang='python'>
In [10]:
show_plot('https://plot.ly/~Matlab-demos/3')
Out [10]:
</pre>
<p><center><iframe id="igraph" src="https://plot.ly/~Matlab-demos/3/400/320/" width="400" height="320" seamless="seamless" scrolling="no"></iframe></center><br />
Check out more examples interactive Plotly and Matlab graphs in IPython notebooks <a target="_blank" rel="nofollow" href="http://nbviewer.ipython.org/github/plotly/IPython-plotly/tree/master/">here</a>.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/plotly-graphs-in-ipython-notebook">Plotly graphs in IPython Notebook</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/plotly-graphs" rel="bookmark" title="Plotly graphs">Plotly graphs </a> <small>Plotly charts can be created and customized in Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jfreechart-graphs-and-gauges" rel="bookmark" title="JFreeChart graphs and gauges">JFreeChart graphs and gauges </a> <small>JFreeChart is an open-source charting library that can easily be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/pinning-annotations-to-graphs" rel="bookmark" title="Pinning annotations to graphs">Pinning annotations to graphs </a> <small>Annotation object can be programmatically set at, and pinned-to, plot axes data points. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-axes-part-5-origin-crossover-and-labels" rel="bookmark" title="Customizing axes part 5 &#8211; origin crossover and labels">Customizing axes part 5 &#8211; origin crossover and labels </a> <small>The axes rulers (axles) can be made to cross-over at any x,y location within the chart. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/plotly-graphs-in-ipython-notebook/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Plotly graphs</title>
		<link>https://undocumentedmatlab.com/articles/plotly-graphs?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=plotly-graphs</link>
					<comments>https://undocumentedmatlab.com/articles/plotly-graphs#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 05 Dec 2013 00:00:24 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Commercial]]></category>
		<category><![CDATA[Plotly]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4455</guid>

					<description><![CDATA[<p>Plotly charts can be created and customized in Matlab. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/plotly-graphs">Plotly graphs</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/plotly-graphs-in-ipython-notebook" rel="bookmark" title="Plotly graphs in IPython Notebook">Plotly graphs in IPython Notebook </a> <small>Plotly graphs can be embedded in an IPython Notebook directly from Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jfreechart-graphs-and-gauges" rel="bookmark" title="JFreeChart graphs and gauges">JFreeChart graphs and gauges </a> <small>JFreeChart is an open-source charting library that can easily be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/pinning-annotations-to-graphs" rel="bookmark" title="Pinning annotations to graphs">Pinning annotations to graphs </a> <small>Annotation object can be programmatically set at, and pinned-to, plot axes data points. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-histogram-plots" rel="bookmark" title="Customizing histogram plots">Customizing histogram plots </a> <small>Basic bar charts and histogram plots can be customized in important aspects. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>I would like to welcome Chris Parmer of <a rel="nofollow" href="http://plot.ly" target="_blank">plot.ly</a>, who will describe the integration of Plotly graphs and charts in Matlab. Unlike the open-source <a href="/articles/jfreechart-graphs-and-gauges/" target="_blank">JFreeChart</a> and <a href="/articles/waterloo-graphics/" target="_blank">Waterloo</a> plotting libraries that were described here in the past, Plotly is a commercial (not open-source) service. Contact Plotly for the exact license terms and costs. However, as you can see below, there&#8217;s a demo account that you can freely use. While I do not directly endorse Plotly as a commercial operation, I love its beautiful visualizations and interactivity. I think MathWorks would be wise to copy ideas from Plotly to Matlab&#8217;s graphics library, esp. new chart types and the interactivity features. In the future I hope that either Plotly concepts get included in Matlab&#8217;s HG, or that Plotly plots become embeddable in Matlab GUI (or both).</i><br />
Plotly is a new web-based graphing application. You can interactively make, style, analyze and share beautiful graphs. Here is an example (move your mouse over the graph to see the interactive effects): <br />
<center><iframe loading="lazy" width="800" height="389" seamless="seamless" scrolling="no" src="https://plot.ly/~YairAltman/0/"></iframe><br />
Full size: <a target="_blank" rel="nofollow" href="https://plot.ly/~chris/1638/">https://plot.ly/~chris/1638/</a><br />
</center><br />
<span id="more-4455"></span><br />
Additional examples: <a href="https://plot.ly/~bchartoff/603/" target="_blank">https://plot.ly/~bchartoff/603/</a>, <a target="_blank" rel="nofollow" href="https://plot.ly/~jackp/1000/">https://plot.ly/~jackp/1000/</a> and <a rel="nofollow" href="http://washingtonpost.com/blogs/wonkblog/wp/2013/06/14/do-low-taxes-on-the-rich-leave-the-middle-class-with-lower-wages/" target="_blank">Washington Post</a>.</p>
<h3 id="create">Creating Plotly graphs in Matlab</h3>
<p>Plotly has a Matlab interface. From Matlab, you send data to plotly where it will be stored and made into a graph that you view in your browser. Let&#8217;s get started.</p>
<ol>
<li><a rel="nofollow" href="https://github.com/plotly/MATLAB-api/releases/download/0.4/plotly.zip" target="_blank">download</a> the Plotly-Matlab API package.<br />
&nbsp;</li>
<li>Add folder and subfolders to your Matlab path:
<pre lang='matlab'>
path_to_downloaded_folder = '/User/chris/Downloads/plotly'; % fill in with your path
addpath(genpath(path_to_downloaded_folder))
</pre>
</li>
<li>Sign up through the API, or sign-in with a demo account:
<pre lang='matlab'>
% To sign up, run:
r = signup('my_desired_plotly_username', 'my_desired_plotly_username@my_email.com') % plotly generates a temp password and api_key for you
signin(r.un, r.api_key); % then, sign in with your newly created account
% OR to use the demo account, do:
plotly_username = 'MATLAB_example' % a demo username you can use
plotly_key = 'h5n38rzyjo' % a demo api key you can use
signin(plotly_username, plotly_key)  % sign in to plotly
</pre>
</li>
<li>Create a new chart using the API&#8217;s <i><b>plotly</b></i> function:
<pre lang='matlab'>
% Here's a simple line chart example:
>> x = linspace(0, 6*pi, 100);
>> y1 = exp(-0.2*x).*sin(x);
>> y2 = exp(-0.3*x).*sin(x);
>> r = plotly(x,y1,x,y2) % call plotly instead of plot
High five! You successfully sent some data to your account on plotly.
View your plot in your browser at https://plot.ly/~MATLAB_example/3 or inside your plot.ly account where it is named 'plot from API (3)'
ans =
   url: 'https://plot.ly/~MATLAB_example/3'
   message: [1x205 char]
   warning: [1x0 char]
   filename: 'plot from API (3)'
   error: [1x0 char]
</pre>
</li>
</ol>
<p>And here&#8217;s the graph that you just generated: <a rel="nofollow" href="https://plot.ly/~MATLAB_example/3" target="_blank">https://plot.ly/~MATLAB_example/3</a><br />
Note that the graph won&#8217;t actually appear in a Matlab figure, nor can it be viewed in Matlab&#8217;s limited built-in browser (<i><b>web</b></i>). Instead, you view all of your plots in your &#8220;real&#8221; web browser, at the URL that plotly has returned. You can also have Matlab automatically open up the browser by running <code>dos(['open ' r.url])</code> on a Mac, or <code>dos(['start ' r.url])</code> on Windows. Within a webpage, you can embed it using an <code>iframe</code> tag (as I have done in this article), as follows:</p>
<pre lang='html'><iframe loading="lazy" width="800" height="400" seamless="seamless" scrolling="no" src="https://plot.ly/~MATLAB_example/3"></iframe></pre>
<p>Here is a side-by-side comparison with the corresponding Matlab plot:<br />
<center><figure style="width: 800px" class="wp-caption aligncenter"><a target="_blank" href="/images/Plotly1.gif"><img loading="lazy" decoding="async" alt="Corresponding Matlab and Plotly plots (click for details)" src="https://undocumentedmatlab.com/images/Plotly1_800x308.jpg" title="Corresponding Matlab and Plotly plots (click for details)" width="800" height="308" /></a><figcaption class="wp-caption-text">Corresponding Matlab and Plotly plots (click for details)</figcaption></figure></center></p>
<h3 id="customize">Customizing Plotly graphs</h3>
<p>Every aspect of the plotly graph can be customized online. This means no more 500-line styling scripts! To open up the plot into the GUI, click the &#8220;Save a copy&#8221; button. You can also download the graphs to EPS, SVG, PNG, and PDF:<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><a target="_blank" href="/images/Plotly2.gif"><img loading="lazy" decoding="async" alt="Web-based Plotly chart customization (click for details)" src="https://undocumentedmatlab.com/images/Plotly2_450x329.jpg" title="Web-based Plotly chart customization (click for details)" width="450" height="329" /></a><figcaption class="wp-caption-text">Web-based Plotly chart customization (click for details)</figcaption></figure></center><br />
Plotly can make line charts, scatter plots, histograms, 2D histograms, box plots, heatmaps, and error bars. They also support log axes, date axes, multiple axes and subplots.<br />
Plotly&#8217;s graphing syntax is a little unconventional. Plots are described with cell arrays of structs. Each struct describes a single &#8220;trace&#8221; of the plot with data, chart-type, and optional styling information. There are no setters or getters (Why? Well, because behind the scenes, the data gets converted to a JSON object and the closest analogue of a JSON array of key-value pair objects in Matlab is a cell array of structs). For example:</p>
<pre lang='matlab'>
samples = randn(500,1); % 500 normally distributed samples
trace1 = struct('y', samples, ...
                'type', 'histogramy', ... % make a histogram type plot
                'histnorm', 'probability density'); % normalized by probability density distribution
trace2 = struct('x', linspace(-3,3,100), ...
                'y', 1./sqrt(2*pi)*exp(-linspace(-3,3,100).^2/2.), ...
                'fill', 'tozeroy') % "fill" the curve to the "zero-y" line i.e. make an area plot
response = plotly({trace1, trace2});  % => https://plot.ly/~MATLAB_example/5
</pre>
<p><center><iframe loading="lazy" width="400" height="250" seamless="seamless" scrolling="no" src="https://plot.ly/~YairAltman/1/"></iframe></center><br />
Now let&#8217;s make some graphs not generally seen in Matlab 🙂<br />
First, triple y-axis:</p>
<pre lang='matlab'>
x = linspace(0,6*pi,100);
trace1 = struct('x',x, 'y',sin(x).*exp(-0.3*x));
trace2 = struct('x',x, 'y',10*sin(x-2*pi/3).*exp(-0.3*x), 'yaxis','y2'); % this trace will correspond to 2nd y-axis, 'y2'
trace3 = struct('x',x, 'y',100*sin(x-4*pi/3).*exp(-0.3*x), 'yaxis','y3'); % this trace will correspond to 3rd y-axis, 'y3'
layout = struct('xaxis', struct('domain',[0,0.9]), ... % set x-axis to span 90% of plot width, like Matlab's 'Position' property
                'yaxis2', struct('anchor','x', 'side','right', 'overlaying','y'), ... % places another y-axis on the right side of the plot
                'yaxis3', struct('anchor','side', 'right','free', 'position',1.0, 'overlaying','y')) % places 3rd y-axis at 100% plot width
r = plotly({trace1, trace2, trace3}, struct('layout', layout));  % => https://plot.ly/~MATLAB_example/13
dos(['open ', r.url])
</pre>
<p><center><iframe loading="lazy" width="500" height="350" seamless="seamless" scrolling="no" src="https://plot.ly/~YairAltman/3/"></iframe></center><br />
Try clicking and dragging on the y-axis (along the number lines). Notice how each axes is totally independent of the other trace. Panning is done by dragging the x-axis. Also, try zooming (click-and-drag).<br />
Here&#8217;s another neat example of how subplots&#8217; axes can be linked to each other or can be independent:</p>
<pre lang='matlab'>
x1 = [1, 2, 3];  y1 = [2,3,4];
x2 = [20,30,40]; y2 = [3,4,5];
x3 = [2, 3, 4];  y3 = [600,700,800];
x4 = [4000,5000,6000]; y4 = [7000,8000,9000];
% build structs describing the plot traces and assigning data to axes
trace1 = struct('x',x1, 'y',y1);
trace2 = struct('x',x2, 'y',y2, 'xaxis','x2', 'yaxis','y');  % new x-axis but same y-axis as trace1; 'x2' is shorthand for 'xaxis2' below
trace3 = struct('x',x3, 'y',y3, 'xaxis','x',  'yaxis','y3'); % same x-axis as trace 1 but a new y-axis
trace4 = struct('x',x4, 'y',y4, 'xaxis','x4', 'yaxis','y4'); % new x-axis and new y-axis
% build a layout struct describing the layout of the different axes
xaxis =  struct('domain', [0, 0.45]); % let the first x-axis span the first 45% of the plot width
yaxis =  struct('domain', [0, 0.45]); % and let the first y-axis span the first 45% of the plot height
xaxis2 = struct('domain', [0.55, 1]); % and let the second axis span the latter 45% of the plot width
yaxis3 = struct('domain', [0.55,1]);
xaxis4 = struct('domain', [0.55, 1], 'anchor','y4'); % anchor axis vertical position to start of yaxis4
yaxis4 = struct('domain', [0.55, 1], 'anchor','x4'); % anchor axis horizontal position to start of xaxis4
layout = struct('xaxis',xaxis, 'yaxis',yaxis, 'xaxis2',xaxis2, 'yaxis3',yaxis3, 'xaxis4',xaxis4, 'yaxis4',yaxis4);
r = plotly({trace1,trace2,trace3,trace4}, struct('=> layout', layout))  % => https://plot.ly/~MATLAB_example/15
dos(['open ', r.url])
</pre>
<p><center><iframe loading="lazy" width="500" height="300" seamless="seamless" scrolling="no" src="https://plot.ly/~YairAltman/2/"></iframe></center><br />
The bottom two plots share the same y-axis, the two stacked plots on the left share the same y-axis, the two stacked plots on the left share the same x-axis and the plot in the top right has its own x and y axes. Try zooming (click-and-drag), auto-scaling (double-click), or axis panning (click-and-drag on the axes number lines) around in the different plots and see how the axes respond.<br />
In case you don&#8217;t have the Matlab Stats toolbox, you can use plotly to make your box plots:</p>
<pre lang='matlab'>
y1 = randn(50,1); y2 = rand(50,1);
r = plotly({struct('y',y1, 'type','box'), struct('y',y2, 'type','box')}) % => https://plot.ly/~MATLAB_example/17
dos(['open ', r.url])
</pre>
<p><center><iframe loading="lazy" width="450" height="230" seamless="seamless" scrolling="no" src="https://plot.ly/~YairAltman/4/"></iframe></center><br />
In case you don&#8217;t have the Matlab Bioinformatics toolbox or Yair&#8217;s <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/16181-datamatrix"><i><b>DataMatrix</b></i> utility</a>, you can use plotly to make your heatmaps:</p>
<pre lang='matlab'>
r = plotly({struct('z',randn(50,50), 'type','heatmap')}) % => https://plot.ly/~matlab_example/18
dos(['open ', r.url])
</pre>
<p><center><iframe loading="lazy" width="450" height="200" seamless="seamless" scrolling="no" src="https://plot.ly/~YairAltman/5/"></iframe></center><br />
Or, a different type of heat-map (<a target="_blank" rel="nofollow" href="https://plot.ly/~jackp/1000/">click here for details</a>):<br />
<center><iframe loading="lazy" width="570" height="500" seamless="seamless" scrolling="no" src="https://plot.ly/~YairAltman/6/"></iframe></center><br />
This was an introduction to the plotly-Matlab interface. Plotly is bridging desktop-based technical computing with the modern web. Inside the tool itself, you can share graphs and data with others (similarly to Google Docs), view revisions of your graph and data (similarly to GitHub), and even make graphs without coding by uploading a CSV, Excel, or even a .mat file. Since it&#8217;s entirely web-based, you can share your graphs and data with a link to anyone, even if they don&#8217;t have Matlab. There are also similar interfaces in Python, R, Perl, Julia, and Arduino, so if you or if you and your colleagues like to work in different languages, you can keep all of your data and graphs in the same place, online.<br />
Last but not least, it&#8217;s much easier to make beautiful, publication-quality graphs. Here are some of our favorite examples:<br />
Graphs: <a rel="nofollow" href="https://plot.ly/~carmeloosh/66/" target="_blank">plot.ly/~carmeloosh/66/</a>, <a rel="nofollow" href="http://plot.ly/~flann321/9/" target="_blank">plot.ly/~flann321/9/</a>, <a rel="nofollow" href="https://plot.ly/~carmeloosh/81/" target="_blank">plot.ly/~carmeloosh/81/</a>, <a rel="nofollow" href="https://plot.ly/~carmeloosh/83/" target="_blank">plot.ly/~carmeloosh/83/</a>, <a rel="nofollow" href="http://plot.ly/~demos/444" target="_blank">plot.ly/~demos/444</a>, <a rel="nofollow" href="http://plot.ly/~demos/390" target="_blank">plot.ly/~demos/390</a><br />
Scripts: <a rel="nofollow" href="https://plot.ly/MATLAB/script-demos/fractal-barnsley-fern-graph-example/" target="_blank">plot.ly/MATLAB/script-demos/fractal-barnsley-fern-graph-example/</a>, <a rel="nofollow" href="https://plot.ly/MATLAB/script-demos/math-scores-boxplot-line-chart-example/" target="_blank">plot.ly/MATLAB/script-demos/math-scores-boxplot-line-chart-example/</a></p>
<h3 id="resources">Additional resources</h3>
<ul>
<li>Online-documentation: <a rel="nofollow" href="https://plot.ly/api/MATLAB/" target="_blank">https://plot.ly/api/MATLAB/</a></li>
<li>An online gallery: <a rel="nofollow" href="https://plot.ly/api/MATLAB/gallery/" target="_blank">https://plot.ly/api/MATLAB/gallery/</a></li>
<li>Plotly File Exchange utility: <a rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/42202-plotly-api" target="_blank">http://www.mathworks.com/matlabcentral/fileexchange/42202-plotly-api</a></li>
<li>The Matlab interface is open source on GitHub: <a rel="nofollow" href="https://github.com/plotly/MATLAB-api" target="_blank">https://github.com/plotly/MATLAB-api</a> (note that the plotly engine is not open-source, only the API)</li>
<li>Plotly&#8217;s homepage: <a rel="nofollow" href="https://plot.ly/" target="_blank">https://plot.ly/</a></li>
<li>Email: chris [at] plot [dot] ly</li>
</ul>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/plotly-graphs">Plotly graphs</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/plotly-graphs-in-ipython-notebook" rel="bookmark" title="Plotly graphs in IPython Notebook">Plotly graphs in IPython Notebook </a> <small>Plotly graphs can be embedded in an IPython Notebook directly from Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jfreechart-graphs-and-gauges" rel="bookmark" title="JFreeChart graphs and gauges">JFreeChart graphs and gauges </a> <small>JFreeChart is an open-source charting library that can easily be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/pinning-annotations-to-graphs" rel="bookmark" title="Pinning annotations to graphs">Pinning annotations to graphs </a> <small>Annotation object can be programmatically set at, and pinned-to, plot axes data points. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-histogram-plots" rel="bookmark" title="Customizing histogram plots">Customizing histogram plots </a> <small>Basic bar charts and histogram plots can be customized in important aspects. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/plotly-graphs/feed</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
