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

조회 수: 8 (최근 30일)
Patryk
Patryk 2025년 8월 20일
댓글: Star Strider 2025년 8월 20일
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.
.
  댓글 수: 2
Patryk
Patryk 2025년 8월 20일
That actually works great, definitely makes it looks a bit more organised. Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (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