Bar width doesn't work when plotting two bar plots
조회 수: 8 (최근 30일)
이전 댓글 표시
When I try to plot two similar but different distributions using bar over each other, setting 'BarWidth' to 1 does not seem to have the desired effect. For example, executing the code shown below, the second, red bar plot will still have spaces between it.
f1 = randn(10000,1);
f2 = f1;
f1s = sort(f1);
f2(end+1:end+500) = f1s((end-499):end)+rand(500,1);
[hf2, bf2] = hist(f2,20);
[hf1, bf1] = hist(f1,20);
b2 = bar(bf2,hf2);
hold on
b1 = bar(bf1,hf1);
set(b2,'FaceColor','g','BarWidth',1);
set(b1,'FaceColor','r','BarWidth',1.000001);
Anyone know why this is and how to solve it?
I've noticed that when I add a very small number to the 1 it will get rid of the space between the bars (as long as it is larger then the machine precision). So I've been using this as a work around, but this seems like a clunky work around.
Best
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Bar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!