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