How can I plot a histogram and line on the same plot in MATLAB 7.11 (R2010b)?
5 views (last 30 days)
Show older comments
MathWorks Support Team
on 9 Sep 2010
I would like to plot both a histogram and a line on the same plot. I have tried using the 'hold on' command, but the scales of the plots are quite different. I would like them to be plotted with separate scales.
Accepted Answer
MathWorks Support Team
on 9 Sep 2010
It is possible to plot to lines with separate scales using the PLOTYY command. Once could get the handle to an axis generated by PLOTYY and replace the line plot with a histogram. After plotting the histogram, the y-axis can be rescaled as appropriate. the following code demonstrates this:
x1=1:10;
y1=10*rand(1,1000);
x=1:10;
y=rand(1,10);
axes=plotyy(x,y,x,y);
hold on
hist(axes(1),y1,x1);
ylim(axes(1),'auto');
set(axes(1),'ytickmode','auto');
hold off
0 Comments
More Answers (0)
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!