MATLAB Answers

0

Y-axis labels overlaps with figure when using a reversed x-axis

Asked by Attila Fülöp on 11 Apr 2019
Latest activity Answered by David Wilson on 11 Apr 2019
Heya,
In Matlab 2018B, when plotting data with a reversed x-axis, the y-axis ticks and labels appear over the figure in a nasty fashion.
Minimal example:
figure(1);
plot(gca,0:10,(0:10).^10);
set(gca,'xdir','reverse')
Capture.PNG
Is there a way to force an offset? Or to fix it in another way?

  0 Comments

Sign in to comment.

Products


Release

R2018b

2 Answers

Answer by David Wilson on 11 Apr 2019
Edited by David Wilson on 11 Apr 2019

Yes, it seems to only happen when there is an exponent in the y-axis. And even then the exponent must have double figures. Also the same happens (on the x-axis) when reversing the y-axis.
One really ugly fix is to extract the ylabels and pad them with a few spaces (on the right).
hp = plot(gca,0:10,(0:10).^10);
set(gca,'xdir','reverse')
yt = yticklabels;
for i=1:length(yt)
yt{i} = [yt{i},' ']; % note pad with a few spaces
end
yticklabels(yt)
Plot now looks like
test.png

  1 Comment

I could accept this hack maybe, do you know of a way to keep the "10^9" label visible at the same time?

Sign in to comment.


Answer by David Wilson on 11 Apr 2019

Ah, missed that. Nasty bug/feature.
text(10,10.5e9,'x10^9') % place manually ?

  0 Comments

Sign in to comment.