how to plot histograms on

  • Follow


top of each other? I have two vectors, and I would like to plot two histograms representing these vectors on the same plot. Any suggestions? I would like the bins of the histogram to be transparent. Also is there a way to put a CDF plot on the same Figure? 
0
Reply jenya 11/18/2010 11:17:03 PM

On 10-11-18 05:17 PM, jenya polyakova wrote:
> top of each other? I have two vectors, and I would like to plot two
> histograms representing these vectors on the same plot. Any suggestions?

If you want them to overlay each other, then use the standard "hold on" .

If you want them to be offset from each other, then when you use bar() to plot 
the histograms, specify {different} explicit x values if you want the 
separation to be on the x axis; for separation on the y axis, you would add a 
constant to the y values for the second series and then after you had created 
the bar object for the second series, you would set the BaseValue property for 
the series to the constant that you shifted by.

> I would like the bins of the histogram to be transparent.

In current versions of matlab, bar() returns a hggroup object that has 
Children, with each child being a patch object. You can set the alpha 
transparency for each of the patch objects (there will, if I recall, be one 
patch object per column.)

 > Also is there
> a way to put a CDF plot on the same Figure?

cdf -- sure, "hold on"


Note: the above techniques apply to reasonably recent version of Matlab; I 
haven't happened to see a response from you yet about which Matlab you are 
using; possibly your version uses a slightly different technique for bar plots.
0
Reply Walter 11/18/2010 11:40:40 PM


> top of each other? I have two vectors, and I would like to plot two 
> histograms representing these vectors on the same plot. Any suggestions? I 
> would like the bins of the histogram to be transparent. Also is there a 
> way to put a CDF plot on the same Figure?

You got advice about this, but I want to suggest using kernel density 
estimates instead of histograms. They're easier to superimpose. Try this for 
an example:

load fisheriris
[y,x] = ksdensity(meas(1:50,1)); plot(x,y,'b-')
hold on; [y,x] = ksdensity(meas(51:100,1)); plot(x,y,'r-')
[y,x] = ksdensity(meas(101:150,1)); plot(x,y,'g-'); hold off

-- Tom 

0
Reply Tom 11/19/2010 4:01:20 PM

2 Replies
392 Views

(page loaded in 0.099 seconds)

Similiar Articles:













7/29/2012 7:16:38 AM


Reply: