Azzera filtri
Azzera filtri

xticks and yticks with decimal exponents

3 visualizzazioni (ultimi 30 giorni)
Sim
Sim il 8 Giu 2023
Commentato: Sim il 8 Giu 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)])

Risposta accettata

Star Strider
Star Strider il 8 Giu 2023
Modificato: Star Strider il 8 Giu 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.
.

Più risposte (1)

Dyuman Joshi
Dyuman Joshi il 8 Giu 2023
Modificato: Dyuman Joshi il 8 Giu 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 Commento
Sim
Sim il 8 Giu 2023
thanks a lot both @Star Strider and @Dyuman Joshi...!!!! Please consider I would have accepted both answers...!!

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by