How can I change the interval on the y-axis?
320 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Pul
el 16 de Ag. de 2021
Comentada: Pul
el 16 de Ag. de 2021
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.
0 comentarios
Respuesta aceptada
Scott MacKenzie
el 16 de Ag. de 2021
Editada: Scott MacKenzie
el 16 de Ag. de 2021
Here's some example code on how to control the "ticks":
x = 1:5;
y = randi(100, 1, 5);
plot(x,y);
set(gca, 'ylim', [0 100]);
set(gca, 'ytick', 0:5:100);
plot(x,y);
set(gca, 'ylim', [0 100]);
set(gca, 'ytick', 0:25:100);
plot(x,y);
set(gca, 'ylim', [0 100]);
set(gca, 'ytick', 0:20:100);
Más respuestas (2)
Pul
el 16 de Ag. de 2021
4 comentarios
Scott MacKenzie
el 16 de Ag. de 2021
Editada: Scott MacKenzie
el 16 de Ag. de 2021
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.
Steven Lord
el 16 de Ag. de 2021
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)
0 comentarios
Ver también
Categorías
Más información sobre Axis Labels en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!