Histogram - problem with X axis (shifting the data)
조회 수: 6 (최근 30일)
이전 댓글 표시
I plotted a histogram which represent three data: A, B, C. The A represent the sum of B+C. I think there is something wrong with X axis (they are shifted for every data), because the C data for some values is higher than A. Does anyone know what can be wrong in my code?
% Generate histogram
h0=histogram(C,'BinLimits',[0.00,3.00],'FaceColor',[0.8 0.8 0.8],'EdgeColor','none','FaceAlpha',1);
hold on
h1=histogram(A,'BinLimits',[0.00,3.00],'FaceColor',[0 0 0],'EdgeColor','none','FaceAlpha',1);
hold on
h2=histogram(B,'BinLimits',[0.00,3.00],'FaceColor',[0.3 0.3 0.3],'EdgeColor','none','FaceAlpha',0.7);
hold on
xlim([0.1,1.4]);
댓글 수: 2
Image Analyst
2016년 1월 9일
What is your C data? Is it the counts you're talking about, or the bin edges?
Or is it the actual C, which you say is equal to A+B. If B is negative then C could be less than A for a particular element.
채택된 답변
Guillaume
2016년 1월 11일
My guess is that since you leave histogram to choose its own bins, your histograms don't have exactly the same bins. You can check the bins with:
h0.BinEdges %it would make more sense to call h0: hC
h1.BinEdges %it would make more sense to call h1: hA
h2.BinEdges %it would make a lot more sense to call h2: hB
If that is indeed the problem, either fix the bins to start with, or reuse the bins of the first histogram in the seconds and thid:
hC = histogram(C, 'BinLimits',[0.00,3.00],'FaceColor',[0.8 0.8 0.8],'EdgeColor','none','FaceAlpha',1);
hold on
hA = histogram(A, hc.BinEdges, 'BinLimits',[0.00,3.00],'FaceColor',[0 0 0],'EdgeColor','none','FaceAlpha',1);
hB = histogram(B, hc.BinEdges, 'BinLimits',[0.00,3.00],'FaceColor',[0.3 0.3 0.3],'EdgeColor','none','FaceAlpha',0.7);
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!