How can I plot a histogram with a logarithmic X-axis?

493 views (last 30 days)
I would like to plot a histogram of my data, with the x-axis being logarithmic, such as in semilogx

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The ability to directly plot a histogram with a logarithmic x-axis is not available in MATLAB.
To work around this issue, use the HIST function to plot the histogram, and them use
set(gca,'xscale','log')
to set the x-axis scale to logarithmic.

More Answers (2)

Ofer Kimchi
Ofer Kimchi on 31 Aug 2018
In order to get evenly spaced bins, you can use:
[~,edges] = histcounts(log10(x));
histogram(x,10.^edges)
set(gca, 'xscale','log')

Hieu Nguyen
Hieu Nguyen on 11 Apr 2022
histogram(log10(yourdata))
xticklabels(num2cell(10.^get(gca,'XTick')));

Tags

No tags entered yet.

Products


Release

R2006a

Community Treasure Hunt

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

Start Hunting!