フィルターのクリア

xticks and yticks with decimal exponents

3 ビュー (過去 30 日間)
Sim
Sim 2023 年 6 月 8 日
コメント済み: Sim 2023 年 6 月 8 日
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)])

採用された回答

Star Strider
Star Strider 2023 年 6 月 8 日
編集済み: Star Strider 2023 年 6 月 8 日
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.
.

その他の回答 (1 件)

Dyuman Joshi
Dyuman Joshi 2023 年 6 月 8 日
編集済み: Dyuman Joshi 2023 年 6 月 8 日
% 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 件のコメント
Sim
Sim 2023 年 6 月 8 日
thanks a lot both @Star Strider and @Dyuman Joshi...!!!! Please consider I would have accepted both answers...!!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by