Plotting error bars on a two Y axis graph

Plotting error bars on a two Y axis graph

Post by Stu Fillma » Fri, 16 Jan 2009 05:05:18


Hi Everyone
I am using the plotyy command to create a graph with two y axes. Since there is no error bar command using this function I attempted to put hold on and plot overtop using the errorbar command and specifying which axes I wanted. It works fine for the first (left axis) but then on the second I get an error message.

??? Error using ==> get
Invalid handle object.

Error in ==> nextstyle at 23
co = get(ax,'ColorOrder');

Error in ==> errorbar at 101
[ls,c,m] = nextstyle(cax,autoColor,autoStyle,k==1);

Error in ==> gammapowergammacountcorr at 95
errorbar(Axis3(2),xaxisarray,meancounton(:),serr_counton(:),'go')

We traced this back to the fact that errorbar itself is not supposed to take axes commands as its first argument. Does anyone out there know how I could go about plotting error bars on my YY graph? Thanks in advance for any help that can be offered.
 
 
 

Plotting error bars on a two Y axis graph

Post by Paul Menne » Fri, 16 Jan 2009 15:18:01

> I am using the plotyy command to create a graph with two y axes.

It's possible to get plotyy to plot error bars in the manner you want,
however in my opinion you have to be a graphics expert to coerce
plotyy to do anything more than the most basic plots. An alternative
to plotyy that I would like to recommend - you can find on the file
exchange by searching for "plt". One of the main advantages to plt
is the consistent interface, exhaustively documented with dozens of
examples.

The example that you should look at is called "pltvbar.m" (in the demo
folder) and it shows how to plot vertical bars of several types including
error bars. Any trace or combination of traces may be placed on either
the right or left hand axis (specified via the 'Right' parameter).

If you have any questions or problems with plt, feel free to contact the
author (me) at: paul (at) mennen (dot) org.

~Paul

 
 
 

Plotting error bars on a two Y axis graph

Post by Wilfrie » Mon, 02 May 2011 05:24:04


I used the following sequence to generate a polt you are looking for:

fig = figure;
[AX,H1,H2] = plotyy(Wopen, MeanAbsNoise, Wopen, WopenOverE);

set(fig, 'CurrentAxes', AX(1));
hold on;
errorbar(Wopen, MeanAbsNoise, Err, 'r.');

set(fig, 'CurrentAxes', AX(2));
hold on;
errorbar(Wopen, WopenOverE, Err2, 'r.');

grid on;

Best Regards
HoWil