How can you shift the position of x axis labels?

67 visualizaciones (últimos 30 días)
L'O.G.
L'O.G. el 22 de En. de 2023
Comentada: Star Strider el 23 de En. de 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?

Respuesta aceptada

Star Strider
Star Strider el 23 de En. de 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 comentarios
L'O.G.
L'O.G. el 23 de En. de 2023
Thank you so much
Star Strider
Star Strider el 23 de En. de 2023
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by