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

조회 수: 23 (최근 30일)
the cyclist
the cyclist 2015년 5월 18일
편집: Star Strider 2015년 5월 18일
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?

답변 (1개)

Star Strider
Star Strider 2015년 5월 18일
편집: Star Strider 2015년 5월 18일
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]')

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by