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

9 Ansichten (letzte 30 Tage)
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

Star Strider
Star Strider am 20 Aug. 2025
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
Patryk
Patryk am 20 Aug. 2025
That actually works great, definitely makes it looks a bit more organised. Thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by