McClean: Plotyy with Errorbar: Difference between revisions

From OpenWetWare
Jump to navigationJump to search
No edit summary
Line 15: Line 15:
set(get(a(2),'Xlabel'),'String','Points')
set(get(a(2),'Xlabel'),'String','Points')
title('Two Errorbar Plots')
title('Two Errorbar Plots')
</pre>
</pre>


[[Image:Ex1_TwoErrorBar]]





Revision as of 10:10, 30 January 2012

Summary

This simple (very simple) function is used with plotyy so that you can make an errorbar plot (or two) on a plot with two y-axis.

Example

Examples of how to use the code:

Example 1: Plotting two errorbar plots with the same x-axis and different y-axis

M1=randn(100,10);
M2=randn(100,10);
x=linspace(1,10,10);
[a,h1,h2]=plotyy(x,M1,x,M2,'EBplotyy','EBplotyy');
set(get(a(1),'Ylabel'),'String','Data 1')
set(get(a(2),'Ylabel'),'String','Data 1')
set(get(a(2),'Xlabel'),'String','Points')
title('Two Errorbar Plots')

File:Ex1 TwoErrorBar


Example 2: Plotting one errorbar plot and a non-errorbard plot on the same x-axis with different y axis



Code

function h=EBplotyy(x,y)
%INPUT:
%x-independent variable (often Time)
%y-dependent variable
%OUTPUT:
%h-handle of the errorbar graphics object
%
%Save this code in an m-file named EBplotyy.m

s=nanstd(y);
h=errorbar(x,nanmedian(y),nanstd(y));  %NOTE: You might want to change nanmedian to nanmean, nanstd to standard error, etc depending on what you want to plot

Notes

Please feel free to post comments, questions, or improvements to this protocol. Happy to have your input!

  • Megan N McClean 17:27, 30 January 2012 (EDT): Obviously this is nothing fancy, but the code has come in handy for me a number of times, so I thought I would stick it on the wiki in case it is useful to anyone else in the lab.

References

Mathworks Online Help: plotyy

Matlab Newsreader: Plotyy with errorbar

Contact

or instead, discuss this protocol.