The farthest yticklabels do not appear when using ax.YAxisLocation = 'origin'

조회 수: 5 (최근 30일)
The two farthest ytickslabels (in this case both -1 and +1), do not show up if I use ax.YAxisLocation = 'origin'
x=-1:0.1:1;
plot(x,x,'o-')
ax=gca;
ax.YAxisLocation = 'origin';
set(ax,'fontsize',20)
yticks([-1 -0.5 0 0.5 1])
Is there a way to show them without playing with ylim([-2 2]) as here below?
x=-1:0.1:1;
plot(x,x,'o-')
ax=gca;
ax.YAxisLocation = 'origin';
set(ax,'fontsize',20)
yticks([-1 -0.5 0 0.5 1])
ylim([-2 2])

채택된 답변

Les Beckham
Les Beckham 2024년 6월 24일
I'm not sure this is much more satisfactory than your approach, but it appears to at least work and would adapt to different y axis ranges.
It's interesting that the 'ylimitmethod' and 'xlimitmethod' work differently for their default values of 'tickaligned'. Maybe because the x labels are outside the axis and thus have more room to be displayed.
x=-1:0.1:1;
plot(x,x,'o-')
grid on
ax=gca;
ax.YAxisLocation = 'origin';
set(ax,'fontsize',20)
yticks([-1 -0.5 0 0.5 1])
set(gca, 'ylimitmethod', 'padded')
% ylim([-2 2])

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by