Reputation: 73
I want to draw a histogram, using plot(histcounts(X,edges))
.
It works fine, except that on the x-axis, the number of the bin is displayed, not the actual value the bin refers to.
To make a bit clearer what I mean, I append two plots. Both display the same data, but for the first one, I used plot(histcounts(X,edges))
and for the second hist(X,edges)
. The plot for which I used hist shows the x-axis the way I want it to look like, with the value the bin refers to. I would like the plot(histcount(...)
to have the same x-axis, instead of showing the bin number.
Histogram using plot(histcounts)
:
How can I change the x-axis to show this value instead of the bin number?
Thanks a lot!
Upvotes: 1
Views: 2701
Reputation: 1439
If you have the edges, you can get the centres using
centres = edges(1:end-1)+ diff(edges)/2;
then the plot can be
plot(centres, histcounts(X,edges));
If you do not need to specify the edges you can get them using
[h_counts, edges] = histcounts(X);
Upvotes: 1