How can you shift the position of x axis labels?

69 vues (au cours des 30 derniers jours)
L'O.G.
L'O.G. le 22 Jan 2023
Commenté : Star Strider le 23 Jan 2023
I can generate a scatter plot with the x axis labels of type categorical or string. When I rotate them slightly, I would like the end of the label to line up with the tick mark on the x axis, which is not currently the case. How can I do this?

Réponse acceptée

Star Strider
Star Strider le 23 Jan 2023
They’re probably text objects, however it’s not possible to access their properties. The only way to change them is to get them, delete them frm the axes, and use the text function to put them where you want them by setting the 'HorizontalAlignment'. 'VerticalAlignment', and other properties.
xc = categorical({'A1','A2','A3','A4','A5'});
figure
scatter(xc,rand(5,size(xc,2)), 'filled')
colormap(turbo)
Ax = gca;
xtl = get(Ax,'XTickLabel');
set(Ax,'XTickLabel',[])
yl = ylim;
text(1:numel(xtl), ones(size(xtl))*(yl(1)-0.025*diff(yl)), xtl, 'Horiz','center', 'Vert','top', 'Rotation',30)
.
  2 commentaires
L'O.G.
L'O.G. le 23 Jan 2023
Thank you so much
Star Strider
Star Strider le 23 Jan 2023
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by