semilogx() with reverse X Axis changes Y Labels position

So when i try to plot a semilogx(...) with reverse xaxis something strange happens to the y Labels and i dont know how to fix this.
for example:
figure
y = ones(1,10000);
semilogx(y)
and then when i try to change the XDir property this happens:
set(gca,'XDir','reverse')
All the y ticks are on top of the y axis and i dont find any property to move them to the correct place.

2 Comments

Which release, OS? Doesn't happen here w/ R2017b on Win7
Windows 10 Enterprise, Matlab 2018b

Sign in to comment.

 Accepted Answer

That is a bug that has been fixed in R2019a (and perhaps earlier).
The only workaround seems to be to create separate 'YTickLabel' strings with spaces to the right to offset them from the y-axis:
figure;
plot(gca,0:2);
set(gca,'XDir','reverse')
yt = get(gca, 'YTick');
ytl = sprintfc('%.1f ', yt);
set(gca, 'YTick',yt, 'YTickLabel',ytl)
Change the spaces in the sprintfc format dexcriptor to get the result you want. (The sprintfc function is undocumented. You can also use the compose function if you have it.)

2 Comments

I am using Matlab 2018b.. so it seems 2019a fixes that,
yeah i also thougt about that solution but i hoped that there would be a bether solution like changing the position of the labels... but Thanks :)

Sign in to comment.

More Answers (0)

Products

Release

R2018b

Community Treasure Hunt

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

Start Hunting!