McClean: Making Nice Bar Plots: Difference between revisions

From OpenWetWare
Jump to navigationJump to search
Line 4: Line 4:
=Example=
=Example=
Suppose you have some experimental data from two strains under four different experiment conditions the means and standard deviations of which look like:
Suppose you have some experimental data from two strains under four different experiment conditions the means and standard deviations of which look like:
<pre>
<pre>
Strain1_Mean=[0.5137    3.2830    1.5887    5.9188];
Strain1_Mean=[0.5137    3.2830    1.5887    5.9188];

Revision as of 15:25, 8 June 2012

Summary

This explains the basics of making pretty bar plots in Matlab. The Matlab "bar" command is used, along with some nice scripts discovered on the Matlab file exchange.

Example

Suppose you have some experimental data from two strains under four different experiment conditions the means and standard deviations of which look like:

Strain1_Mean=[0.5137    3.2830    1.5887    5.9188];
Strain2_Mean=[0.4042    2.9884    0.5709    2.7766];
Strain1_std=[1.1393    2.8108    2.2203    3.5233];
Strain2_std=[0.8762    2.8478    0.9878    2.2197];


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

M1=randn(100,10);
x=linspace(1,10,10);
y=2*x;
[a,h1,h2]=plotyy(x,M1,x,y,'EBplotyy','plot')
set(get(a(1),'YLabel'),'String','Errorbar Plot')
set(get(a(2),'YLabel'),'String','Some Other Plot')
title('Errorbar Plot and some other Random Plot')
set(get(a(1),'XLabel'),'String','Points')

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.