How can you shift the position of x axis labels?

69 Ansichten (letzte 30 Tage)
L'O.G.
L'O.G. am 22 Jan. 2023
Kommentiert: Star Strider am 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?

Akzeptierte Antwort

Star Strider
Star Strider am 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)
.

Weitere Antworten (0)

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by