how expand plots with different x-axis ranges

조회 수: 7 (최근 30일)
Salvatore Savastano
Salvatore Savastano 2019년 12월 9일
편집: Adam Danz 2019년 12월 11일
Hi folks,
I have a problem with plot some distributions. I have two bar plots with different x-range values: one of them is contained in the other but it's smaller and so when I try to plot both only one is clearly visible while the other is shown as a "spike". How can I do to visualize both of them?
Togive a better idea about my question I have attached the two plot shown separately and I would like to have both on the same figure avoiding the "spike" effect.plot_test1.png
plot_test2.png
Thank you in advance for your help

채택된 답변

Adam Danz
Adam Danz 2019년 12월 9일
Specify the edges for both histograms rather than letting that funciton choose the bins.
If the data from histrogram #2 only covers a very tiny range of the data from histogram #1, it may not be easy to see two different distributions plotted on the same axes.
If this advice doesn't solve the problem you'll have to provide a few lines that reproduces the problem (the data and the code you're using).
  댓글 수: 2
Salvatore Savastano
Salvatore Savastano 2019년 12월 9일
편집: Salvatore Savastano 2019년 12월 9일
Dear Adam,
thank you for your reply.
<<If the data from histrogram #2 only covers a very tiny range of the data from histogram #1, it may not be easy to see two different distributions plotted on the same axes. >>
You have centred my problem: the data of histogram #1 (red) is a smaller interval of data of histogram #2 (blu). When I try to plot both on the same figure the smaller one becomes a sort of "spike" and it's not possible to see its distribution. Of course, if I try to zoom the area around the spike, th e distribution will appear again but the other one (the blu) won't be anymore visible. I would like to find a way to show both distributions.
The code I'm using is the following:
map = brewermap(2,'Set1');
figure;
title('Probability Density Function', 'FontSize',16);
xlabel('Pixel magnitude [dB]', 'FontSize',16);
ylabel('Probability density', 'FontSize',16);
axis tight;
b1 = bar(gxp1, 3*gyp1/max(gyp2), 1,'FaceColor',map(1,:),'FaceAlpha',0.5);
hold on
b2 = bar(gxp2, gyp2, 1,'FaceColor',map(2,:),'FaceAlpha',0.5);
Adam Danz
Adam Danz 2019년 12월 10일
편집: Adam Danz 2019년 12월 11일
Where does those first two inputs come from in bar() ?
Why not use histogram where you can specify the bar width. The suggestion in my answer would definitely make the bars visible for both distributions but there may be a lot fewer bars for 1 group than the other.
Alternatively you could scale the width parameter in bar(___,width)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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