Reversing y axis direction causes xticks to invert and overlap with labels
Show older comments
I just switched from 2015a to 2018b and encounted a problem with the xticks and corresponding labels whenever I invert the y-axis. The Xtick direction seems reversed from the set value (in or out) and they overlap with the labels. I have no clue how to fix this.
Thanks!
subplot(1,3,1)
plot(rand(10,1),rand(10,1).*(1E-8))
subplot(1,3,2)
plot(rand(10,1),rand(10,1).*(1E-8))
set(gca,'Ydir','reverse')
subplot(1,3,3)
plot(rand(10,1),rand(10,1).*(1E-8))
set(gca,'Ydir','reverse')
set(gca,'TickDir','out')
4 Comments
Star Strider
on 21 Nov 2018
That’s definitely a bug.
Use the ‘Contact Us’ link at the top right corner of this page to report it. Include a link to the URL of your Question here so you don’t have to repeat it.
Kelly Hokanson
on 21 Nov 2018
Star Strider
on 21 Nov 2018
My pleasure!
Consider posting the MathWorks reply in a Comment here.
Kelly Hokanson
on 21 Nov 2018
Edited: Kelly Hokanson
on 21 Nov 2018
Accepted Answer
More Answers (2)
Stefanie Schwarz
on 22 Mar 2021
Edited: Stefanie Schwarz
on 22 Mar 2021
This is a bug in R2018b that was fixed in R2019a. See the following Bug Report:
A workaround is to set the Y-axis label to text and insert spaces.
Example:
>> set(gca, 'YTickLabel', {'0 ', '1 ', '2 ', '3 ', '4 '})
Robert Weigel
on 13 May 2021
Adding an empty subscript worked for the case when the x-tick labels have exponents.
xtl = get(gca,'XTickLabel'); % {'10^{1}', '10^{2}'}
for i = 1:length(xtl)
xtl{i} = [xtl{i},'_{ }']; % Append empty subscript
end
set(gca,'XTickLabel',xtl);
Categories
Find more on Axis Labels 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!