Scientific notation at y-axis with "ax.YAxis.Exponent"

44 ビュー (過去 30 日間)
Mepe
Mepe 2021 年 6 月 11 日
コメント済み: Mepe 2021 年 6 月 14 日
I want to change the notation of the log y-axis:
Here is an example code, which doesn't work:
y = [0.1 0.3 0.5 1];
figure(1),
plot(y)
yticks([0.1 0.5 1])
set(gca,'yscale','log')
ax = gca;
ax.YAxis.Exponent = 2
I found out that exponent notation doesn't work when yticks is used in conjunction with logarithmic scaling.
Any ideas???

採用された回答

dpb
dpb 2021 年 6 月 11 日
Well, here's a crude first pass...
expn=floor(log10(yticks));
mant=yticks./10.^(expn);
lbls=cellstr(num2str([mant;expn].','%d*10^{%d}'));
lbls=strrep(lbls,'1*','')
lbls =
3×1 cell array
{'10^{-1}' }
{'5*10^{-1}'}
{' 10^{0}' }
>>
Then
yticklabels(lbls)
produces
Salt to suit; no guarantees on how general will turn out to be...
  13 件のコメント
Walter Roberson
Walter Roberson 2021 年 6 月 14 日
round. I did not want to assume that log10(0.001) was guaranteed to be exactly -3
Mepe
Mepe 2021 年 6 月 14 日
Dear Walter and dpb,
thanks a lot for your support!

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

その他の回答 (1 件)

dpb
dpb 2021 年 6 月 11 日
I don't see a user-settable format to force the notation (although I didn't use Yair's getundoc to poke) with arbitrary tick values but
yticks(10.^(-1:1))
will trigger redrawing with the desired notation.
It's having intermediate tick labels that causes the switch.
  2 件のコメント
Mepe
Mepe 2021 年 6 月 11 日
Thanks for the answer, but I would like to set the individual ticks myself ...
dpb
dpb 2021 年 6 月 11 日
Well, you can have one or the other, not both automagically.

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

カテゴリ

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