Help with axes labels on histogram plot
25 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nadeau Hahne
le 6 Nov 2023
Réponse apportée : Steven Lord
le 6 Nov 2023
Hello,
I am simply trying to add labels to this histogram under the the middle of the columns and I am unable to figure out how to add for the other two columns.

histogram(F)
title('Distribution of Traction Forces')
xticks(0.0135)
xticklabels("0.149")
yticks(1:5)
1 commentaire
Dyuman Joshi
le 6 Nov 2023
"... I am unable to figure out how to add for the other two columns."
Supply the values for the other two columns as well, along with the first one.
Réponse acceptée
Image Analyst
le 6 Nov 2023
You're manually telling it to do just one tick label. Let it do it automatically and you'll get them. Get rid of the calls to xticks and xticklabels.
F = [.149, .194, .298*ones(1, 5), 3*.149];
histogram(F)
title('Distribution of Traction Forces')
xlabel('Value');
ylabel('Count');
0 commentaires
Plus de réponses (1)
Steven Lord
le 6 Nov 2023
If you want the labels to be only in the center of the bars, use the BinEdges property of the histogram to compute where the ticks should be. I'll make a histogram with 17 bins (so the math doesn't work out quite so nicely.)
x = randn(1, 1e5);
n = 17;
h = histogram(x, n);
This has n+1 (in this case, 18) edges.
E = h.BinEdges
Use diff to compute the width of each bin (or for uniform bins, like this histogram has, use the BinWidth property.)
W = h.BinWidth % or
W = diff(E)
Each bin center is the left edge plus half the bin width. But the last bin edge isn't involved at this step; we don't need the "center" that's past the right edge of the histogram.
C = E(1:end-1) + W/2
Now set those ticks.
xticks(C)
0 commentaires
Voir également
Catégories
En savoir plus sur Data Distribution Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

