<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/260973</link>
    <title>MATLAB Central Newsreader - plot second y axis on the fly</title>
    <description>Feed for thread: plot second y axis on the fly</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 16 Sep 2009 14:28:03 -0400</pubDate>
      <title>plot second y axis on the fly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/260973#680561</link>
      <author>andy </author>
      <description>I would like to plot a second y axis (right side) on the fly and furthermore want multiple data sets referred to for the left axis (or either axis for that matter) and want to be able to have error bars. I bounce among many computers with default installations and would rather avoid plt. plotyy also doesn't seem to have this capacity (at least with reference to having multiple sets on each side, some with error bars and some without), but this seems like such a basic need that I feel like I am missing something. My immediate need is to, in Command Window, do something like:&lt;br&gt;
&lt;br&gt;
figure&lt;br&gt;
plot(x1,y1,'bo') %left axis&lt;br&gt;
hold on&lt;br&gt;
errorbar(x2,y2,e2,'ro') %left axis&lt;br&gt;
errobar(x3,y3,e3,'g-') %where this one would be on the RIGHT AXIS &lt;br&gt;
&lt;br&gt;
Thank you for your time.&lt;br&gt;
&lt;br&gt;
andy</description>
    </item>
    <item>
      <pubDate>Wed, 16 Sep 2009 16:38:02 -0400</pubDate>
      <title>Re: plot second y axis on the fly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/260973#680598</link>
      <author>arich82 </author>
      <description>&quot;andy &quot; &amp;lt;ecoandy@yahoo.com&amp;gt; wrote in message &amp;lt;h8qslj$51t$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I would like to plot a second y axis (right side) on the fly and furthermore want multiple data sets referred to for the left axis (or either axis for that matter) and want to be able to have error bars. I bounce among many computers with default installations and would rather avoid plt. plotyy also doesn't seem to have this capacity (at least with reference to having multiple sets on each side, some with error bars and some without), but this seems like such a basic need that I feel like I am missing something. My immediate need is to, in Command Window, do something like:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; figure&lt;br&gt;
&amp;gt; plot(x1,y1,'bo') %left axis&lt;br&gt;
&amp;gt; hold on&lt;br&gt;
&amp;gt; errorbar(x2,y2,e2,'ro') %left axis&lt;br&gt;
&amp;gt; errobar(x3,y3,e3,'g-') %where this one would be on the RIGHT AXIS &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thank you for your time.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; andy&lt;br&gt;
&lt;br&gt;
Use the handles returned by plotyy.&lt;br&gt;
&lt;br&gt;
I'm not sure why you only have one set of data [x1, y1]; do the differently scaled error bars e2 and e3 both apply to y1, or should there have been a [x4, y4]?  Regardless, you could replace NaN's in the following example with [x4, y4] if that's what you meant:&lt;br&gt;
&lt;br&gt;
%%&lt;br&gt;
x1 = linspace(0, 2*pi, 101);&lt;br&gt;
y1 = sin(x1);&lt;br&gt;
&lt;br&gt;
x2 = x1(1:10:end);&lt;br&gt;
y2 = sin(x2);&lt;br&gt;
e2 = ones(size(x2));&lt;br&gt;
&lt;br&gt;
x3 = x1(5:10:end);&lt;br&gt;
y3 = 10*sin(x3);&lt;br&gt;
e3 = 10*ones(size(x3));&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
hf = igure;&lt;br&gt;
[ha, h1, h2] = plotyy(x1, y1, NaN, NaN)&lt;br&gt;
set(h1, 'Marker', 'o');&lt;br&gt;
&lt;br&gt;
hold(ha(1), 'all');&lt;br&gt;
hold(ha(2), 'all');&lt;br&gt;
&lt;br&gt;
errorbar(ha(1), x2, y2, e2, 'ro') %left axis&lt;br&gt;
errorbar(ha(2), x3, y3, e3, 'g-') %where this one would be on the RIGHT AXIS &lt;br&gt;
&lt;br&gt;
% Let me know if this does what you need, or if I misinterpreted something.&lt;br&gt;
&lt;br&gt;
--</description>
    </item>
    <item>
      <pubDate>Wed, 16 Sep 2009 16:59:25 -0400</pubDate>
      <title>Re: plot second y axis on the fly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/260973#680609</link>
      <author>Paul Mennen</author>
      <description>&quot;andy &quot; wrote in message&lt;br&gt;
&amp;gt; plotyy also doesn't seem to have this capacity (at least with&lt;br&gt;
&amp;gt; reference to having multiple sets on each side, some with error&lt;br&gt;
&amp;gt; bars and some without),&lt;br&gt;
&lt;br&gt;
Andy, I believe with enough work you can coerce plotyy to do such a thing&lt;br&gt;
although it will be more difficult than it should be. There is an alternative&lt;br&gt;
one the file exchange called plt:&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/4936&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/4936&lt;/a&gt; &lt;br&gt;
&lt;br&gt;
For an example of what you are trying to do (several plots mixing&lt;br&gt;
traces, bars, error bars) try the example &quot;plt\demo\pltvbar.m&quot;.&lt;br&gt;
&lt;br&gt;
Note that you can put as many of the traces on the right hand axis&lt;br&gt;
as you want - e.g. the parameter 'Right',[2 4 5], will put the 2nd,&lt;br&gt;
4th and the 5th traces on the right axis with the remaining on the left.&lt;br&gt;
&lt;br&gt;
If the documentation (plt.chm) doesn't answer all your questions, feel free to ask me:&lt;br&gt;
&lt;br&gt;
paul (at) mennen (dot) org&lt;br&gt;
&lt;br&gt;
I hope that helps you out.&lt;br&gt;
~Paul</description>
    </item>
    <item>
      <pubDate>Thu, 01 Jul 2010 12:15:20 -0400</pubDate>
      <title>Re: plot second y axis on the fly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/260973#759077</link>
      <author>Johannes Drever</author>
      <description>Hi, the correct usage of plotyy is illustrated by the following example. The key is to use anonymous functions:&lt;br&gt;
&lt;br&gt;
figure(1)&lt;br&gt;
clf&lt;br&gt;
&lt;br&gt;
x = -pi:0.1:pi;&lt;br&gt;
&lt;br&gt;
y1 = sin(x);&lt;br&gt;
y2 = cos(repmat(x, 10, 1)) .* 3 + randn(10, length(x));&lt;br&gt;
&lt;br&gt;
[ax, h1, h2] = plotyy(x, y1, x, mean(y2), 'plot', @(x, y) errorbar(x, y, std(y2)));&lt;br&gt;
&lt;br&gt;
cheers,&lt;br&gt;
Johannes</description>
    </item>
  </channel>
</rss>

