How to make side-by-side bars with the histogram() function?

22 views (last 30 days)
When using the now-discouraged hist function to make histograms comparing two data sets, the default display was to put the bars of the two histograms side-by-side.
Now, with the new histogram function, the default behavior is to superimpose the two distributions, with some transparency.
What's the easiest way to get the old side-by-side behavior, while still using the new function?

Answers (1)

Star Strider
Star Strider on 18 May 2015
Edited: Star Strider on 18 May 2015
I doubt that’s possible without some serious hacking.
A work-around:
A = randn(100,2);
[h1,edges] = histcounts(A(:,1), 10);
[h2,edges] = histcounts(A(:,2), 10);
figure(1)
ctrs = edges(1)+(1:length(edges)-1).*diff(edges); % Create Centres
bar(ctrs, [h1 ;h2]')

Tags

Community Treasure Hunt

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

Start Hunting!