How does one use bar() to show multiple bars for a single X-axis value?
Show older comments
bar( [1,2], [10,20;30,40] ); draws a bar graph with two X ticks, 1 and 2. At X=1 there are two bars of height 10 and 20, and at X=2 there are two bars of height 30 and 40.
But what if I want a bar graph with one Xtick showing two bar of height 10 and 20. bar( [1], [10,20] ) doesn't work: "X must be same length as Y"
Is there some trick to getting bar() to work in this case? My code has to work with a wide range of datasets, some of which have the one-xtick case.
Answers (1)
Oleg Komarov
on 27 Jul 2011
bar([10 20; NaN NaN])
set(gca,'xlim',[0 2],'xtick',1)
Categories
Find more on Bar Plots 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!