Filter löschen
Filter löschen

xticks and yticks with decimal exponents

3 Ansichten (letzte 30 Tage)
Sim
Sim am 8 Jun. 2023
Kommentiert: Sim am 8 Jun. 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)])

Akzeptierte Antwort

Star Strider
Star Strider am 8 Jun. 2023
Bearbeitet: Star Strider am 8 Jun. 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.
.

Weitere Antworten (1)

Dyuman Joshi
Dyuman Joshi am 8 Jun. 2023
Bearbeitet: Dyuman Joshi am 8 Jun. 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 Kommentar
Sim
Sim am 8 Jun. 2023
thanks a lot both @Star Strider and @Dyuman Joshi...!!!! Please consider I would have accepted both answers...!!

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by