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

7 次查看(过去 30 天)
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.

采纳的回答

Star Strider
Star Strider 2025-8-20
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.
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

产品


版本

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by