Can I get side-by-side-by-side barh on one axes?

1 view (last 30 days)
I want to create a series of horizontal bar graphs that are horizontally side-by-side.
  • On the x-axis between 0 and 1, the horizontal bar graph for dataset1
  • On the x-axis between 1 and 2 the horizontal bar graph for dataset2
  • On the x-axis between 2 and 3 the horizontal bar graph for dataset3
  • and so on.
These are not 'stacked,' rather each dataset is independent and has it's own distribution that should have a baseline starting from x=0 or x=1 or x=2, and so on.
Plotting them all on the same axes seems to require making the left-hand end of each bar non-zero (except for dataset1), is there an easy way to do this?
I would rather not create new axes for each barh.
Can I use the 'basevalue' property to reset the minimum value on the x-axis? For example:
figure;
hold on
barh(bins, histc(dataset1,bins)/numel(dataset1),'b')
barh(bins,1+histc(dataset2,bins)/numel(dataset2),'g','basevalue',1)

Answers (1)

Matt Tearle
Matt Tearle on 15 Feb 2011
What you've suggested already seems to solve the problem. So is the real issue that you've had to hack the values to start at 1? That is, are you looking for a way to have the x tick values start over at 0? In which case... here's a hack that works for this example:
xt = get(gca,'XTick')
xt(xt>=1) = xt(xt>=1)-1
set(gca,'XTickLabel',num2str(xt'))
In general, I guess, you could do the middle line for k=1:n, using k instead of 1.

Categories

Find more on Discrete Data Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!