visibility range of histogram

34 ビュー (過去 30 日間)
Sajid Afaque
Sajid Afaque 2020 年 6 月 12 日
コメント済み: Walter Roberson 2020 年 6 月 12 日
hello i have 2 questions now,
  1. in below histogram how do i limit the range of x-axis to around 200.(here i am also specifying the number of bins)
2. in below histogram my median value in around 24,is their any possibility where i can indicate this value in the x-axis prior to 25.i used text but i am having difficulties in placing it in the right position(i.e. at median value)

回答 (2 件)

Abhivandan Pandey
Abhivandan Pandey 2020 年 6 月 12 日
Hi Sajid,
For your 1st query, you can make use of the xlim function to set the x-axis limits for the histogram as shown below.
histogram(data);
xlim([0, 200]);
For your 2nd query, you can use xticks and xticklabels as below,
xticks([25])
xticklabels({'median = 25'});
I hope this helps.
Regards,
Abhivandan
  2 件のコメント
Sajid Afaque
Sajid Afaque 2020 年 6 月 12 日
2nd answer
for xticks i am getting below error
Undefined function 'xtick' for input arguments of type 'double'.
Abhivandan Pandey
Abhivandan Pandey 2020 年 6 月 12 日
The xticks function was introduced in R2016b. In earlier releases you must use the code below (this code also works on newer releases)..
set(gca,'XTick',[25])
set(gca,'xticklabel',({'median = 25'}))

サインインしてコメントする。


Walter Roberson
Walter Roberson 2020 年 6 月 12 日
Instead of using 200 bins, you can specify the bin edges, such as
UpperBound = 200;
NumBins = 100;
%histogram did not exist in R2013b
hist(data, linspace(0,UpperBound,NumBins));
%draw reference line at median
med = median(data);
YL = get(gca, 'YLim');
hold on
plot([med;med], YL, 'r');
xlabel(sprintf('x, median = %g', med))
  2 件のコメント
Sajid Afaque
Sajid Afaque 2020 年 6 月 12 日
編集済み: Sajid Afaque 2020 年 6 月 12 日
hello walter,
actually i need to plot hist for full range . that is my data is from 0 to 931(x-axis range) and for this whole range i take around 495 bins.
now for the obtained hist using
hist(data,495)
i need to limit the visibility range.(say x-axis from 0 to 200).i dont want to re-classify bins
Walter Roberson
Walter Roberson 2020 年 6 月 12 日
i need to plot hist for full range
i need to limit the visibility range
Is it correct that you need to plot everything but only put 0 to 200 up in the visible window, and that the reason for that is that you want the user to be able to use the plot tools to be able to zoom or pan to see more of the plot?
If the user is not going to need to see anything after 200 then there is no point in including those bins in the histogram calculation.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2013b

Community Treasure Hunt

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

Start Hunting!

Translated by