Zoomed in and inset histogram

11 ビュー (過去 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 Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by