Last tick labels dissapear when plotting with axes at origin (0,0)

I'm trying to plot a line that has negative and positive x and y values, and therefore would like to include an axes through the origin. When plotting however, the last tick labels from the x and y axes dissapear. Within the window, I can drag the graph left/right or up/down, and the labels reappear, but in the direction I dragged to. The window essentially does not allow the ticks to be displayed. Is there a way I can force the ticks to display over the window? I can force the labels to appear If i slightly increase xlim and ylim, but then I have some of the grid appearing which is annoying. See pics attached.

 Akzeptierte Antwort

After experimenting with this a bit, using:
axis('padded')
might be the best option.
x = linspace(-20, 20, 50);
y = tanh(x/10)/5;
figure
plot(x, y, 'x-')
grid
Ax = gca;
Ax.XAxisLocation = 'origin';
Ax.YAxisLocation = 'origin';
% Ax.XTick = -20:5:20;
% Ax.YTick = -0.2:0.05:0.2;
% axis([-21 21 -0.21 0.21])
axis('padded')
There might also be other options.
.

2 Kommentare

That actually works great, definitely makes it looks a bit more organised. Thank you!
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2025a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by