Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: plot second y axis on the fly
Date: Wed, 16 Sep 2009 16:38:02 +0000 (UTC)
Organization: Michigan Technological University
Lines: 43
Message-ID: <h8r49a$5j9$1@fred.mathworks.com>
References: <h8qslj$51t$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1253119082 5737 172.30.248.35 (16 Sep 2009 16:38:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 16 Sep 2009 16:38:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 378863
Xref: news.mathworks.com comp.soft-sys.matlab:570848


"andy " <ecoandy@yahoo.com> wrote in message <h8qslj$51t$1@fred.mathworks.com>...
> 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:
> 
> figure
> plot(x1,y1,'bo') %left axis
> hold on
> errorbar(x2,y2,e2,'ro') %left axis
> errobar(x3,y3,e3,'g-') %where this one would be on the RIGHT AXIS 
> 
> Thank you for your time.
> 
> andy

Use the handles returned by plotyy.

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:

%%
x1 = linspace(0, 2*pi, 101);
y1 = sin(x1);

x2 = x1(1:10:end);
y2 = sin(x2);
e2 = ones(size(x2));

x3 = x1(5:10:end);
y3 = 10*sin(x3);
e3 = 10*ones(size(x3));


hf = igure;
[ha, h1, h2] = plotyy(x1, y1, NaN, NaN)
set(h1, 'Marker', 'o');

hold(ha(1), 'all');
hold(ha(2), 'all');

errorbar(ha(1), x2, y2, e2, 'ro') %left axis
errorbar(ha(2), x3, y3, e3, 'g-') %where this one would be on the RIGHT AXIS 

% Let me know if this does what you need, or if I misinterpreted something.

--