How can I change the interval on the y-axis?
이전 댓글 표시
Hello everyone,
how can I change the interval on the y-axis?
For istance, if I want to put an interval every 25 or 50.
Thank you.
채택된 답변
추가 답변 (2개)
댓글 수: 4
Scott MacKenzie
2021년 8월 16일
편집: Scott MacKenzie
2021년 8월 16일
You used an answer box for your reply comment. Oops.
In your example, the y-axis limits go from 0 to 1400, and you have asked for ticks at 0, 25, 50, 75, etc., up to 1400. So, of course, the labelling is cluttered. I'm not sure what you are aiming for. What about...
set(gca, 'ylim', 0:100:1400);
That will yield less clutter.
Pul
2021년 8월 16일
Scott MacKenzie
2021년 8월 16일
편집: Scott MacKenzie
2021년 8월 16일
Yes, but this is starting to sound like a different question. And we're commenting here in the answer box. Ouch!
But, to your point, yes, you can plot the data that appear in magenta from the right-side axis. They will have their own limits and will be fully visible. See Create Chart with Two y-Axes for details.
Pul
2021년 8월 16일
You can use the yticks and yticklabels functions to control the locations of the ticks and the labels used for those ticks.
x = 0:0.5:32;
y = x.^2;
plot(x, y)
Let's make a copy of that plot (so you can see the difference when I run the code in MATLAB Answers) and update the tick locations.
figure
plot(x, y)
yticks(0:50:1050)
Let's say I want to put ticks every 50 units but only to label multiples of 100.
figure
plot(x, y)
ticklocations = 0:50:1050;
yticks(ticklocations)
% Create the tick labels from the tick locations
% Or you could use
%
% ticklabels = yticklabels;
ticklabels = string(ticklocations);
% Replace the labels for any tick location that's not a multiple of 100
% with a blank label
ticklabels(mod(ticklocations, 100) ~= 0) = "";
yticklabels(ticklabels)
카테고리
도움말 센터 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






