How can I start the y axis of my plot with 1 but keep increments at 5, 10, 15 and so on?

조회 수: 4 (최근 30일)
Maus
Maus 2017년 8월 15일
편집: Adam 2017년 8월 15일
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
Stephen23
Stephen23 2017년 8월 15일
편집: Stephen23 2017년 8월 15일
"1 but the increment is set at 6, 11 and so on."
That is correct if you set the step to 5. Think about the differences between the values.
Do you really need a special case for the first value?
Maus
Maus 2017년 8월 15일
I just want it to look like the right picture. 6, 11,... as increments don't look good. I'd maybe like to have a special case for the first increment which should only be 4 numbers above the first one but each one after that to be set 5 numbers higher.

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

답변 (2개)

Adam
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.
  댓글 수: 6
Maus
Maus 2017년 8월 15일
I get this error message again:
Value must be a vector of type single or double whose values increase
Error in plotwaterfall (line 20)
hAxes.YTick = [ 1 hAxes.YTick ];
Adam
Adam 2017년 8월 15일
편집: Adam 2017년 8월 15일
If you are using 0 as the lower y limit then
hAxes.YTick(1) = 1;
should work instead. Again though, if the plot will change after the initial plotting this can get messy.

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


Star Strider
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)])

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by