Borrar filtros
Borrar filtros

xticks and yticks with decimal exponents

3 visualizaciones (últimos 30 días)
Sim
Sim el 8 de Jun. de 2023
Comentada: Sim el 8 de Jun. de 2023
How to reproduce exactly these axes?
% My attemot
plot(10^(0):10^(3),10^(-8):10^(3))
set(gca, 'XScale', 'log', 'YScale', 'log');
xticks([10^(0) 10^(0.5) 10^(1) 10^(1.5) 10^(2)])
yticks([10^(-7.5) 10^(-5) 10^(-2.5) 10^(0) 10^(2.5)])

Respuesta aceptada

Star Strider
Star Strider el 8 de Jun. de 2023
Editada: Star Strider el 8 de Jun. de 2023
Use the compose function to create a separate set of tick labels —
% My attemot
plot(10^(0):10^(3),10^(-8):10^(3))
set(gca, 'XScale', 'log', 'YScale', 'log');
xticks([10^(0) 10^(0.5) 10^(1) 10^(1.5) 10^(2)])
xtl = compose('10^{%g}',[0 0.5 1 1.5 2]); % 'compose' Call
xticklabels(xtl)
ytl = compose('10^{%g}',[(-7.5) (-5) (-2.5) (0) (2.5)]); % 'compose' Call
yticklabels(ytl)
You can also do:
yticklabels(compose('10^{%g}',[(-7.5) (-5) (-2.5) (0) (2.5)]))
I kept them separate here to illustrate it and so you can see what the compose result looks like on its own. (Note the use of the '%g' edit descriptor.)
EDIT — (7 Jun 2023 at 12:06)
Forgot about the x-tick lables. Added now.
.

Más respuestas (1)

Dyuman Joshi
Dyuman Joshi el 8 de Jun. de 2023
Editada: Dyuman Joshi el 8 de Jun. de 2023
% My attempt
%You can directly plot on log vs log scale via loglog()
loglog(10^(0):10^(3),10^(-8):10^(3))
%set(gca, 'XScale', 'log', 'YScale', 'log');
vecx = 0:0.5:3; %modified
vecy = -7.5:2.5:2.5;
%define x and y ticks
xticks(10.^vecx)
yticks(10.^vecy)
%define text corresponding to the labels
strx = compose("10^{%g}", vecx);
stry = compose("10^{%g}", vecy);
%define tick labels using the text
xticklabels(strx)
yticklabels(stry)
%Turn off the minor ticks
set(gca,'XMinorTick','off','YMinorTick','off')
  1 comentario
Sim
Sim el 8 de Jun. de 2023
thanks a lot both @Star Strider and @Dyuman Joshi...!!!! Please consider I would have accepted both answers...!!

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by