How to creat nonlinear bin histogram/bar plot with same Bar width?

6 ビュー (過去 30 日間)
En
En 2014 年 5 月 2 日
回答済み: mirza 2016 年 12 月 26 日
I am try to plot a histogram with uneven space bars in definition ( Logarithmic etc.), but I want all bar looks same width instead. Thanks for sharing the method to do it.

採用された回答

Star Strider
Star Strider 2014 年 5 月 2 日
Here is one way to use regular-width bins spaced logarithmically:
x = 10+2*randn(1, 100); % Create data
bins = linspace(floor(min(x)), ceil(max(x)), 25); % Define bins
xc = histc(x,bins); % Do histogram counts
figure(1)
bar(log(bins), xc) % Plot bars against log of ‘bins’
logxts = get(gca, 'XTick') % 'XTick' values currently logarithmic
expxts = exp(logxts); % Take antilog to use them as new ‘XTickLabels’
set(gca, 'XTickLabel', floor(100*expxts)/100)
The plot:
This produces logarithmic X-axis values (scaling and labels) for the bar plot. If you want to experiment with other transformations, be sure you can uniquely inverse-transform them to get the X-axis labels.
  2 件のコメント
En
En 2014 年 5 月 2 日
Thx a lot!
Star Strider
Star Strider 2014 年 5 月 2 日
My pleasure!
That was a very interesting problem.

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

その他の回答 (1 件)

mirza
mirza 2016 年 12 月 26 日
You basically need to do 2 things:
1- Make the bin edges follow a logarithmic scale.
2- Set the x-axis to logarithmic scale.
y=100*rand(1000,1); % create random data
x=logspace(-1,2,20); % create bin edges with logarithmic scale
histogram(y,x); % create the plot
set(gca,'xscale','log'); % scale the x-axis

カテゴリ

Help Center および File ExchangeModel Building and Assessment についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by