plotyy with bar graphs
3 views (last 30 days)
Show older comments
I have two data sets with completely different scales that I would like to plot as bar plots. say, y1 = linspace(1,10,10) and y2 = linspace(100000,1000000,10) and x = 1:10. If I use plotyy(x,y1,x,y2,@bar,@bar), I get 2 bar plots that are stacked and the same color. I would like the bar plots to be grouped with different colors for each bar series. Ive been searching for at least an hour, but frankly, most of the workarounds are complicated and suck. Your help is much appreciated. Thanks.
0 Comments
Answers (1)
dpb
on 7 Jul 2014
Edited: dpb
on 7 Jul 2014
plotyy is somewhat limited in that it can only take the two sets of x,y data so you have two choices --
a) make custom function that takes care of the desired customization but itself is callable by plotyy (I recall S Lord gave an example here not terribly long ago as in a few months at most that illustrated the idea nicely; sorry I can't recall the exact title), or
b) forego plotyy and draw the two axes individually. This really isn't as hard as it seems; and there's an example in the graphics help files section on enhancements that illustrates it.
Oh, and I guess there's a third...
c) take the basic bar that plotyy gives and then mung on the properties. With bar I suspect this is the least pleasant of the choices; for line plots it's generally straightforward and it may be w/ bar but I don't use it often enough to be particularly adept with it so I always struggle to get what I want that way...
ADDENDUM
Above is link to a thread where I posted S Lord's solution using anonymous functions for plotyy arguments. In the subject case it was fill instead of bar, but the idea's the same.
0 Comments
See Also
Categories
Find more on Two y-axis 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!