How to change x-axis ticks labels in stackedplot?
Show older comments
h = stackedplot(rand(6,3));
I want to set x-axis ticks according to my own defined set i.e., instead of 1:6, I want to replace x-axisticks [1, 2,3 ,4,5,6] to ['A', 'S','T', 'AAA', 'BBB', 'ZZZ'] , by rotating it to 90 degree that is vertically insted of horizontally?
Accepted Answer
More Answers (2)
Simon Allosserie
on 6 Apr 2022
Edited: Simon Allosserie
on 6 Apr 2022
1 vote
Use xtick and xticklabels to change to the A, S, T, ... labels
I don't understand what you further mean with the rotating 90° though.
1 Comment
ikushou
on 3 Nov 2022
No you can not use it when you use stackedplot.
that's really annoying
Paul Carchipulla-Morales
on 8 Feb 2023
1 vote
There is a quicker method that worked for me using NodeChildren in MATLAB2021b.
h = stackedplot(rand(6,3));
ax = findobj(h.NodeChildren, 'Type','Axes');
set(ax,'XTick',[1:6],'XTickLabel',{'A', 'S','T', 'AAA', 'BBB', 'ZZZ'})

2 Comments
Aboltabol
on 27 Jun 2024
Does not work in 2023A or later.
SmokeTheDrone
on 20 Feb 2025
Setting the XTick worked for me in 2024b. Thanks Paul!
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
