<?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>Commercial &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/commercial/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 17 Feb 2016 18:00:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>Simple GUI Tabs for Advanced Matlab Trading App</title>
		<link>https://undocumentedmatlab.com/articles/simple-gui-tabs-for-advanced-matlab-trading-app?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=simple-gui-tabs-for-advanced-matlab-trading-app</link>
					<comments>https://undocumentedmatlab.com/articles/simple-gui-tabs-for-advanced-matlab-trading-app#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 17 Feb 2016 18:00:40 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Toolbox]]></category>
		<category><![CDATA[Alex Boykov]]></category>
		<category><![CDATA[Commercial]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6275</guid>

					<description><![CDATA[<p>A new File Exchange utility enables to easily design GUI tabs using Matlab's GUIDE</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/simple-gui-tabs-for-advanced-matlab-trading-app">Simple GUI Tabs for Advanced Matlab Trading App</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/advanced-matlab-online-webinars" rel="bookmark" title="Advanced Matlab online webinars">Advanced Matlab online webinars </a> <small>Several live online webinars on advanced Matlab programming will be presented in September-October 2017. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class" rel="bookmark" title="Creating a simple UDD class">Creating a simple UDD class </a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/advanced-jide-property-grids" rel="bookmark" title="Advanced JIDE Property Grids">Advanced JIDE Property Grids </a> <small>JIDE property grids can use complex cell renderer and editor components and can signal property change events asynchronously to Matlab callbacks...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/real-time-trading-system-demo" rel="bookmark" title="Real-time trading system demo">Real-time trading system demo </a> <small>A real-time Matlab-based end-to-end trading system demo is presented ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>I&#8217;d like to introduce guest blogger Alex Boykov, one of the developers of the <a href="http://wfatoolbox.com/undocumentedmatlab/" rel="nofollow" target="_blank">Walk-Forward Analysis Toolbox for Matlab (WFAToolbox)</a>, which enables accelerated trading strategies development using Matlab. Today, Alex will explain how they used tabs in a way that can be replicated by any other Matlab GUI, not necessarily having the latest Matlab release.</i><br />
In this post, we want to tell you about how we solved the problem of tab creation for WFAToolbox. We required the following criteria:</p>
<ul>
<li>The tabs need to be attractive and look like tabs, not like buttons with panels</li>
<li>The tabs need to have been drawn using the editor GUIDE so that the contents of the tab panel can be easily edited</li>
<li>The tabs can be easily added and removed without significant code additions. They must be simple to use in different projects and tasks</li>
</ul>
<p>The sophisticated user of Matlab might think that this is a trivial objective, seeing as <a href="http://www.mathworks.com/matlabcentral/fileexchange/?term=tabpanel" target="_blank" rel="nofollow">there are numerous solutions for this problem in the Matlab Exchange</a> and since Matlab R2014b, it supports creating native tabs with the help of <i><b>uitab</b></i> and <i><b>uitabgroup</b></i> functions. Also, with the addition of <a href="http://www.mathworks.com/matlabcentral/fileexchange/48142-app-designer" target="_blank" rel="nofollow">App Designer</a>, it might appear that this issue will be solved with the new interface for GUI creation; tabs can be created right in the editor. However, in this post, we will attempt to explain why none of the methods above fit the three criteria stated and we will present our own solution for the tabs.<br />
Regardless of the fact that we only took on the problem in 2013, when we first started creating our WFAToolbox, at the moment of writing this article (January 2016), this problem is still a relevant issue for many Matlab users. After the release of R2016a, it is doubtful the problem will be entirely solved. This is why we created our own example of a code which we have released on the Matlab File Exchange (see below).<br />
<center><br />
<a href="http://wfatoolbox.com/undocumentedmatlab/" title="WFAToolbox - Matlab App for Algorithmic Trading" target="_blank" rel="nofollow"><img decoding="async" alt="Tab-enabled WFAToolbox (Matlab app for algorithmic trading)" src="https://undocumentedmatlab.com/images/WFAToolbox-1-testing-tab.gif" title="Tab-enabled WFAToolbox (Matlab app for algorithmic trading)" width="75%" style="max-width: 653px;" /></a></p>
<p class="wp-caption-text">Tab-enabled WFAToolbox (Matlab app for algorithmic trading)</p>
<p></center><br />
<span id="more-6275"></span></p>
<h3 id="tabs">1. The tabs have to look like tabs</h3>
<p>When we created WFAToolbox, our goal was to create an application which would allow everyone interested to create a strategy for trading on the financial markets to be able to do so, along with having the opportunity to use the full potential of Matlab and its progressive tools, including genetic algorithms, parallel computing, econometrics, neural networks, and much, much more (basically, any data analysis that can be done in Matlab). At the same time, we do not want our users to spend time on developing an advanced software environment for testing, analysis, and strategy execution, but rather to do it from an easy-to use GUI. Thus, in WFAToolbox, you can create, test, and, finally, launch your own trading strategy or test a hypothesis within minutes, even with little prior knowledge of Matlab programming.<br />
Of course, in order to fit these features into a single application, guarantee that it would be easy to understand even by beginners, and that it would be simple to operate, it was necessary to pay special attention to the graphic interface. In our opinion, perhaps the most intelligent solution for placing the many controls and functions necessary for sophisticated applications is by creating tabs. Because we knew that we were not the only ones who thought this way, we started looking for examples of codes that were previously created in the Matlab Exchange. We were very surprised when we found only a few solutions, most of which did not even match our first criteria of tab attractiveness! Unfortunately, a majority of them were old and quite unattractive (they looked more like buttons with panels). Even the new App Designer has tabs that in our eyes look more like buttons than tabs.<br />
Having tried a lot of these utilities in our test versions, we came to the conclusion that <a href="http://www.mathworks.com/matlabcentral/fileexchange/6996-tabpanel-constructor-v2-8--2010-" target="_blank" rel="nofollow">Tab Panel Constructor v.2.8</a> would be the best option for us. It fits all three criteria above. In 2013, we used it quite successfully in our first versions of WFAToolbox. Everything looked great, but, unfortunately, it later turned out that the problem was far from being solved.<br />
<center><br />
<a href="http://wfatoolbox.com/undocumentedmatlab/" title="WFAToolbox - Matlab App for Algorithmic Trading" target="_blank" rel="nofollow"><img decoding="async" alt="Tab-enabled WFAToolbox (Matlab app for algorithmic trading)" src="https://undocumentedmatlab.com/images/WFAToolbox-3-settings-tab.png" title="Tab-enabled WFAToolbox (Matlab app for algorithmic trading)" width="75%" style="max-width: 653px;" /></a></p>
<p class="wp-caption-text">Tab-enabled WFAToolbox (Matlab app for algorithmic trading)</p>
<p></center></p>
<h3 id="guide">2. The tabs need to be created through GUIDE</h3>
<p>Unfortunately, with time, it turned out that with the newer version of Matlab it didn&#8217;t work smoothly and the code we wanted to use as our solution practically fell apart in front of us. After adding a couple of elements in GUI, partial formatting was lost and we had to redo everything. The process of adding the tags created a lot of bugs which needed to be solved immediately.<br />
In 2014, we already had more than 500 clients using our application. We started hearing, more and more often, that it would be great if the colors and locations of the tabs could be changed. It turned out that, depending on the operating system and Matlab version, the tab format changes. So, we made the decision to change our tabs.<br />
By that time, a new version of Matlab was released, R2014b. It allowed us to build tabs with the help of the <i><b>uitabgroup</b></i> and <i><b>uitab</b></i> functions. The results looked exactly how we wanted: attractive, pleasant, and appeared like real tabs: <a href="http://www.mathworks.com/products/matlab/matlab-graphics/#user_interfaces_with_tab_panels" target="_blank" rel="nofollow">UI With Tab Panel in Matlab R2014b</a>. However, we were discouraged that they could not be created in GUIDE!<br />
During that time, we were developing a module for WFAToolbox which would allow users to download data from Google Finance: 10,000+ free daily and intraday quotes from 20+ exchanges. Tabs were the easiest to use when switching between downloading free data from Google Finance and downloading custom user data from the Matlab Workspace. But entering so many elements through code and not through an editor? What will happen when we add 100,000+ free historical data from Yahoo Finance for futures, bonds, currency, stocks and others? We didn&#8217;t want to create all of this without the GUIDE editor! This is why we came to the conclusion that it is necessary for us to create a code of tabs, starting from scratch, so that they would correspond with all three of our criteria.<br />
<center><br />
<a href="http://wfatoolbox.com/undocumentedmatlab/" title="WFAToolbox - Matlab App for Algorithmic Trading" target="_blank" rel="nofollow"><img decoding="async" alt="Tab-enabled WFAToolbox (Matlab app for algorithmic trading)" src="https://undocumentedmatlab.com/images/WFAToolbox-4-data-loading.gif" title="Tab-enabled WFAToolbox (Matlab app for algorithmic trading)" width="75%" style="max-width: 600px;" /></a></p>
<p class="wp-caption-text">Tab-enabled WFAToolbox (Matlab app for algorithmic trading)</p>
<p></center></p>
<h3 id="edit">3. The tabs should be easy to add and edit</h3>
<p>We chose the <a href="http://www.mathworks.com/matlabcentral/fileexchange/15193-simple-tab-panel" target="_blank" rel="nofollow">Simple Tab Panel</a>, which has existed in the Matlab File Exchange since 2007, as a base for our new code because we considered it to be the most elegant and attractive example of GUIDE tabs. This solution fit our first two criteria, but we really wanted it to be universal and easy to use. We also wanted to have a simplified process of tab addition and deletion so that instead of having to copy and rewrite a large amount of code and other details, we could just add a single line of code. We wanted to save on labor costs, because we often add new features to WFAToolbox and this includes having to constantly add new elements to existing tabs, as well as adding new tabs.<br />
So, we rewrote the code and created our own universal example so that everyone could use it to their advantage. We uploaded the code to the Matlab File Exchange, where it can be freely downloaded: <a href="http://www.mathworks.com/matlabcentral/fileexchange/54992-simple-optimized-gui-tabs" target="_blank" rel="nofollow">Simple Optimized GUI Tab</a>.<br />
Next, we will describe how to use this code for tab addition and how to use the process for the implementation of tasks.<br />
<center><div class="embed"><iframe src="https://www.youtube.com/embed/sdc6ec2q5X8" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen" rel="nofollow"></iframe></div></center><br />
So, in order to add a new tab, you need to:</p>
<ol>
<li>Open GUIDE and apply <i><b>uipanel</b></i> and <i><b>uitext</b></i> in a way that will make <i><b>uipanel</b></i> easier to work with in the future, and place <i><b>uitext</b></i> in a place where the tab switch will be located.</li>
<li>Rename the <b>Tag</b> of the <i><b>uitext</b></i> to [&#8216;tab&#8217;,N,&#8217;text&#8217;], where N is the tab index. In our example, we are creating the 3rd tab, so our <b>tag</b> would be &#8216;tab3text&#8217;. Using this same principle, [&#8216;tab&#8217;,N,&#8217;Panel&#8217;] needs to be renamed to <b>tag</b> of <i><b>uipanel</b></i> in the &#8216;tab3Panel&#8217;.</li>
<li>Add the name of the new tab to the <code>TabNames</code> variable. In our example, we use &#8216;Tab3&#8217; (but you can use any name).</li>
</ol>
<pre lang="matlab">TabNames = {'Tab 1','Tab 2','Tab3'};</pre>
<h3 id="how">How the code was created</h3>
<p>The primary principle of how our code works is that we create the <i><b>uipanel</b></i> and <i><b>uitext</b></i> objects in GUIDE, then we take the <i><b>uitext</b></i> coordinates and replace the objects to the <strong>axes</strong> and <strong>text </strong>objects. We assign a callback function to them which works when the object is clicked on. The function makes the <i><b>uipanel</b></i>s visible/invisible and changes the colors of tab.<br />
Let&#8217;s look at the function code <a href="http://www.mathworks.com/matlabcentral/fileexchange/54992-simple-optimized-gui-tabs/content/SimpleOptimizedTabs2.m" rel="nofollow" target="_blank"><em>SimpleOptimizedTabs2.m</em></a>, which is part of the Simple Optimized GUI Tab submission.</p>
<h4 id="1">1. Tab settings</h4>
<pre lang="matlab">
% Settings
TabFontSize = 10;
TabNames = {'Tab 1','Tab 2'};
FigWidth = 0.265;
</pre>
<p>If we change the parameters under Settings, we can control the appearance of our GUI and tabs. So, the parameter of <code>TabFontSize</code> changes the font size on the tab switch, and, with the help of <code>TabNames</code> we can rename or add tab names, and with <code>FigWidth</code>, we can determine the normalized width of the GUI.</p>
<h4 id="2">2. Changing the figure width</h4>
<pre lang="matlab">
% Figure resize
set(handles.SimpleOptimizedTab,'Units','normalized')
pos = get(handles. SimpleOptimizedTab, 'Position');
set(handles. SimpleOptimizedTab, 'Position', [pos(1) pos(2) FigWidth pos(4)])
</pre>
<p>The GUI width changes in the code because it isn’t comfortable to manually stretch and narrow the figure. It is more beneficial to see the contents of all tabs and work with them without having to change the width every time you make a small change. If you want to make your <i><b>uipanel</b></i>s bigger than in the example, then do this with the GUIDE editor. However, don’t forget to change the <code>FigWidth</code> parameter.<br />
Please note that, due to the peculiarities of the editor, you cannot narrow a figure by height without shifting tab locations. You can only do this if you are changing the width, so we only recommend adding tabs by increasing the width of the figure and not the length.</p>
<h4 id="3">3. Creating tabs</h4>
<p>Do the following for each tab: obtain the <i><b>uitext</b></i> coordinates, which we entered into the GUI panel, and position the <i><b>axes</b></i> and <i><b>text</b></i> using these coordinates (using the necessary settings of external apparel). Using the <b>ButtonDownFcn</b> parameter, we can link the callback function, called <i>ClickOnTab</i>, in order to switch tabs when clicking on the <b><i>text</i></b> or <i><b>axes</b></i>.</p>
<pre lang="matlab">
% Tabs Execution
handles = TabsFun(handles,TabFontSize,TabNames);
% --- TabsFun creates axes and text objects for tabs
function handles = TabsFun(handles,TabFontSize,TabNames)
% Set the colors indicating a selected/unselected tab
handles.selectedTabColor=get(handles.tab1Panel,'BackgroundColor');
handles.unselectedTabColor=handles.selectedTabColor-0.1;
% Create Tabs
TabsNumber = length(TabNames);
handles.TabsNumber = TabsNumber;
TabColor = handles.selectedTabColor;
for i = 1:TabsNumber
    n = num2str(i);
    % Get text objects position
    set(handles.(['tab',n,'text']),'Units','normalized')
    pos=get(handles.(['tab',n,'text']),'Position');
    % Create axes with callback function
    handles.(['a',n]) = axes('Units','normalized',...
                    'Box','on',...
                    'XTick',[],...
                    'YTick',[],...
                    'Color',TabColor,...
                    'Position',[pos(1) pos(2) pos(3) pos(4)+0.01],...
                    'Tag',n,...
                    'ButtonDownFcn',[mfilename,'(''ClickOnTab'',gcbo,[],guidata(gcbo))']);
    % Create text with callback function
    handles.(['t',n]) = text('String',TabNames{i},...
                    'Units','normalized',...
                    'Position',[pos(3),pos(2)/2+pos(4)],...
                    'HorizontalAlignment','left',...
                    'VerticalAlignment','middle',...
                    'Margin',0.001,...
                    'FontSize',TabFontSize,...
                    'Backgroundcolor',TabColor,...
                    'Tag',n,...
                    'ButtonDownFcn',[mfilename,'(''ClickOnTab'',gcbo,[],guidata(gcbo))']);
    TabColor = handles.unselectedTabColor;
end
% Manage panels (place them in the correct position and manage visibilities)
set(handles.tab1Panel,'Units','normalized')
pan1pos=get(handles.tab1Panel,'Position');
set(handles.tab1text,'Visible','off')
for i = 2:TabsNumber
    n = num2str(i);
    set(handles.(['tab',n,'Panel']),'Units','normalized')
    set(handles.(['tab',n,'Panel']),'Position',pan1pos)
    set(handles.(['tab',n,'Panel']),'Visible','off')
    set(handles.(['tab',n,'text']),'Visible','off')
end
</pre>
<p>Actually, if you have long tab names and you want to change the switch size, then it you may possibly need to correct the <b>Position</b> parameter for the text object by adding the correcting coefficients to it. Unfortunately, this is also a feature of GUIDE. If someone can solve this problem so that the text would always be shown in the middle of the switch tab regardless of the width, we would be happy to read any suggestions in the comments to this post.</p>
<h4 id="4">4. The callback function ClickOnTab</h4>
<p>The callback function <i>ClickOnTab</i> is used every time when clicking on the tab switch and the result of the switches are visible/invisible in the <i><b>uipanel</b></i>s and in changes to the colors of the switches.</p>
<pre lang="matlab">
% --- Callback function for clicking on tab
function ClickOnTab(hObject,~,handles)
m = str2double(get(hObject,'Tag'));
for i = 1:handles.TabsNumber;
    n = num2str(i);
    if i == m
        set(handles.(['a',n]),'Color',handles.selectedTabColor)
        set(handles.(['t',n]),'BackgroundColor',handles.selectedTabColor)
        set(handles.(['tab',n,'Panel']),'Visible','on')
    else
        set(handles.(['a',n]),'Color',handles.unselectedTabColor)
        set(handles.(['t',n]),'BackgroundColor',handles.unselectedTabColor)
        set(handles.(['tab',n,'Panel']),'Visible','off')
    end
end
</pre>
<p>More information about our Walk-Forward Analysis Toolbox for Algorithmic Trading (WFAToolbox) can be found at <a href="http://wfatoolbox.com/undocumentedmatlab/" title="WFAToolbox - Matlab App for Algorithmic Trading" target="_blank" rel="nofollow">wfatoolbox.com</a>.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/simple-gui-tabs-for-advanced-matlab-trading-app">Simple GUI Tabs for Advanced Matlab Trading App</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/advanced-matlab-online-webinars" rel="bookmark" title="Advanced Matlab online webinars">Advanced Matlab online webinars </a> <small>Several live online webinars on advanced Matlab programming will be presented in September-October 2017. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class" rel="bookmark" title="Creating a simple UDD class">Creating a simple UDD class </a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/advanced-jide-property-grids" rel="bookmark" title="Advanced JIDE Property Grids">Advanced JIDE Property Grids </a> <small>JIDE property grids can use complex cell renderer and editor components and can signal property change events asynchronously to Matlab callbacks...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/real-time-trading-system-demo" rel="bookmark" title="Real-time trading system demo">Real-time trading system demo </a> <small>A real-time Matlab-based end-to-end trading system demo is presented ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/simple-gui-tabs-for-advanced-matlab-trading-app/feed</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
			</item>
		<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 loading="lazy" 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>
