Couldn't exploit axis exponent for log scaled axis.

9 次查看(过去 30 天)
I've a plot that has axis values jumping orders of magnitude, which necessitate to plot in log scale. Here is my axes values requirement:
y=[10^-8 5*10^-8 7*10^-8 4*10^-7 9*10^-7]; %y axis
x=[10^-7 10^-6 10^-5 10^-4 10^-3]; %x axis
I specifically want my y axis tick values to be [0.1 0.5 0.7 4.0 9.0] with an exponent at the top having a value of 10^-7. Editing options manually also hasn't favored me. Though I was able to set exponent mode (with value -7) and tick label mode (with format %.2f) (both manually and through code), the same is not reflected in the output for some reasons. Irrespective of many efforts, the tick values prefer to stay in the format of 10 raised to some power. What I've shown here is just a similar code, whereas in my main work the tick values set themselves to 0.00 for all the values. Scratching my head for more than two days, rescue me at the earliest. Warm regards for your kind help!
Here is my complete code for your reference.
loglog(x,y)
hold on
ax = gca;
% ax.YTickMode='manual';
ax.YTickValuesMode='manual';
ax.YTickLabelMode='auto';
ax.ExponentMode='manual';
ax.TickLabelFormatMode='manual';
yticks([10^-8 5*10^-8 7*10^-8 4*10^-7 9*10^-7])
ax.YAxis.Exponent = -7;
ytickformat('%.2f')
hold off
  2 个评论
Voss
Voss 2022-7-16
Note the documentation for NumericRuler properties (in the Exponent property section):
"If the axis has a log scale, then the Exponent property has no effect."
Mithun Sundhar B
Mithun Sundhar B 2022-7-17
Yeah @Voss, you're right. I couldn't convince myself with an answer of why such option is not available for axis with log scale. If you've any explanation, please shed some light. Just curious!

请先登录,再进行评论。

回答(1 个)

dpb
dpb 2022-7-16
You'll have to fake it -- as @Voss notes, the effect you observe (none) is by design -- whether was right choice or not is different question.
loglog(x,y)
hAx=gca;
yl=ylim;
yticklabels(num2str(yticks*1E7,'%0.1f'));
hTxt=text(x(1),yl(2),'10^{-7}','VerticalAlignment',"bottom");
results in
  1 个评论
Mithun Sundhar B
Mithun Sundhar B 2022-7-17
Thanks @dpb for a simple code structure. I did the same manually. I was just wondering why such restriction has been made for log scaled axis. Many thanks!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by