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

3 views (last 30 days)
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?

Answers (2)

David Wilson
David Wilson on 11 Apr 2019
Edited: 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
Attila Fülöp
Attila Fülöp on 11 Apr 2019
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.


David Wilson
David Wilson on 11 Apr 2019
Ah, missed that. Nasty bug/feature.
text(10,10.5e9,'x10^9') % place manually ?

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!