how to change x axis labelling
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
sophp
le 4 Mai 2020
Réponse apportée : Mehmed Saad
le 4 Mai 2020
I have this following bar chart. The subsequent graph returns a bar chart with a labelling of 1,2,3,4,5,6 rather than Q3,Q6,Q10,Q15 etc. How do I fix this?![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/290074/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/290074/image.jpeg)
x=categorical({'Q3','Q6','Q10','Q15','Q30','Q50'});
z=[2.891586318,1.99422657,1.907652812,4.71298388,6.007681496,6.718181667;3.229392123,3.36482536,4.089746011,5.204662107,6.761377397,7.978099976];
y=transpose(z);
a=[0.167797,0.314574,0.081018,0,0.116596,0;0,0.173132,0,0.231752,1.15677,1.204734];
errorplus=a;
errorminus=errorplus;
figure;
bar(x,y);
hBar = bar(y, 0.8);
for k1 = 1:size(y,2)
ctr(k1,:) = bsxfun(@plus, hBar(k1).XData, hBar(k1).XOffset');
ydt(k1,:) = hBar(k1).YData;
end
hold on
errorbar(ctr, ydt, errorplus, '.k')
hold off
ylabel('Signal Intensity','FontSize',18)
set(gca,'linewidth',2,'FontSize',14)
ylim([0 10]);
set(gca,'XTickLabel',x)
1 commentaire
Mohammad Sami
le 4 Mai 2020
I ran your code on R2020a. I am getting the labels as you wanted. Which version of matlab are you using.
Réponse acceptée
Mehmed Saad
le 4 Mai 2020
set(gca,'XTickLabel',x)
This command is working for me
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/290075/image.png)
Maybe due to your MATLAB version it is not working for you
Try converting categorical to cell using cellstr
set(gca,'XTickLabel',cellstr(x))
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Bar 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!