필터 지우기
필터 지우기

Zoomed in and inset histogram

조회 수: 3 (최근 30일)
Ansh
Ansh 2018년 5월 22일
댓글: Ansh 2018년 5월 25일
I have a histogram where I need to zoom along a specific part of the x axis (the actual probabilities in this range of the x axis is extremely low, so the bars get lost when the entire histogram is plotted) and have this subhistogram inset into the original histogram. Can someone please tell me how this can be done? Your help is much appreciated.

채택된 답변

Benjamin Kraus
Benjamin Kraus 2018년 5월 22일
Sounds like you have two questions:
First Question: How do I "zoom in" a histogram?
The answer depends on what exactly you mean by "zoom in", but it sounds like you want to re-bin the data using a smaller range of values. There are a couple ways to do that:
1. There is an optional second input to the histogram command in which you can specify the bin edges. You can use this to specify specific bin edges which span a smaller range than your entire data set. For example:
x = randn(1000,1); % Data will range from roughly -3.5 to 3.5
histogram(x, -1:.1:1); % Bin edges will only include data from -1 to 1.
2. Option 1 hard-codes the bin edges. You can allow the bins to be determined automatically, but still reduce the range, by specifying the BinLimits:
x = randn(1000,1); % Data will range from roughly -3.5 to 3.5
histogram(x, 'BinLimits', [-1 1]); % Bin edges will only include data from -1 to 1.
Second Question: How can I plot a subhistogram inset into the original histogram?
The only way to do this is to create a second, smaller, axes that is manually placed to overlap your main axes. For example:
x = randn(1000,1);
mainax = axes;
histogram(mainax, x, 'BinLimits', [-1 1]);
ylim(mainax, [0 120]) % To make room for sub axes.
subax = axes('Position',[0.2 0.7 0.2 0.2]);
histogram(subax, x);
  댓글 수: 1
Ansh
Ansh 2018년 5월 25일
Yes this is what I wanted and what worked for me. Thank you. I have accepted your answer.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by