How can I control the format of the tick label numbers when using a log YScale with a large range?

I am trying to produce plots with a log Y-axis scale and with non-exponential format numbers (e.g., 1000, not 10^3) as labels for the Y ticks. This works with narrow Y-axis ranges but not wide ones, as is illustrated in the following example (using all positive Y values in quite reasonable ranges):
X = 1:10;
Y = (11:20)*100;
for ymin=400:-100:100
figure;
plot(X,Y);
axis([0 10 ymin 2200]); % set xmin xmax ymin ymax
ax = gca;
ax.YAxis.Exponent = 0
ax.YScale = 'log';
end
Figures 1 and 2 have non-exponential Y tick labels, which is what I want, but Figures 3 and 4 have labels like 10^2.
So, my question is, how can I force MATLAB to produce non-exponential Y tick labels regardless of the range of the Y axis?
Thanks for any suggestions.

 Respuesta aceptada

KL
KL el 17 de Nov. de 2017
Editada: KL el 17 de Nov. de 2017
You should use yticks and yticklabels if you explicitly want to control what is to be displayed.
Something like this in your code should work,
X = 1:10;
Y = (11:20)*100;
for ymin=400:-100:100
figure;
plot(X,Y);
axis([0 10 ymin 2200]); % set xmin xmax ymin ymax
yticks([ymin:100:2200]);
yticklabels(num2str([ymin:100:2200].'));
ax = gca;
ax.YAxis.Exponent = 0
ax.YScale = 'log';
end

1 comentario

Yes, that works, thanks, so I will accept the answer unless a better solution arrives soon.
But I am really hoping for a less "brute force" solution. I'm trying to make a function that I can use to produce a lot of these plots (subplots, actually, with X and Y as arguments), and it would be nice if I could simply rely on MATLAB to produce non-exponential tick labels, rather than having to specify the labels for each subplot individually.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 17 de Nov. de 2017

Comentada:

el 17 de Nov. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by