How can I start the y axis of my plot with 1 but keep increments at 5, 10, 15 and so on?
4 次查看(过去 30 天)
显示 更早的评论
I want the y axis of my plot to start with 1 instead of 0. If I do that with
set(gca,'YTickLabel',0:5:n)
it starts with 0, if I do it instead with
set(gca,'YTickLabel',1:5:n)
it starts with 1 but the increment is set at 6, 11 and so on.
I uploaded a picture to show you exactly what I mean:

2 个评论
回答(2 个)
Adam
2017-8-15
编辑:Adam
2017-8-15
ylim( hAxes, [1 n] );
hAxes.YTick = [ 1 hAxes.YTick ];
should achieve this, though if your plot is dynamic with a changing range it gets more messy when you start manually changing ticks because ticks will no longer update automatically with the range.
I have debated whether to do similar myself often. Sometimes I do, sometimes I don't, especially with images where I want to have nice tick values, but also include the first and last tick explicitly without it giving me silly intermediate ticks. Often it looks a bit odd though.
Star Strider
2017-8-15
Without your data, writing specific code to do what you want can be difficult.
Try this:
x = 0:100; % Create Data
y = bsxfun(@plus, rand(15,101), (1:15)'); % Create Data
figure(1)
plot(x, y)
yt = get(gca, 'YTick');
set(gca, 'YTick',[0 5:5:max(yt)], 'YTickLabel',[1 5:5:max(yt)])
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!