Effacer les filtres
Effacer les filtres

xticks and yticks with decimal exponents

3 vues (au cours des 30 derniers jours)
Sim
Sim le 8 Juin 2023
Commenté : Sim le 8 Juin 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)])

Réponse acceptée

Star Strider
Star Strider le 8 Juin 2023
Modifié(e) : Star Strider le 8 Juin 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.
.

Plus de réponses (1)

Dyuman Joshi
Dyuman Joshi le 8 Juin 2023
Modifié(e) : Dyuman Joshi le 8 Juin 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 commentaire
Sim
Sim le 8 Juin 2023
thanks a lot both @Star Strider and @Dyuman Joshi...!!!! Please consider I would have accepted both answers...!!

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by