フィルターのクリア

number format change in axes of graphs

57 ビュー (過去 30 日間)
LIU
LIU 2014 年 1 月 20 日
コメント済み: Walter Roberson 2020 年 11 月 6 日
I find that numbers on axes will be automatically displayed by common scale factor such as n power of ten when plotting a figure. It seems that n is usually 3 or bigger in absolute. Is it possible to scale it down to 2?
For example, 150 will be automatically displayed as 0.15 as the tick number with 10^3 on top of the y-axis, but it is expected to be 1.5 with 10^2 on top.
But I don't know how to realize it by code?
Could someone have a say? Thank you in advance.
  1 件のコメント
LIU
LIU 2014 年 1 月 22 日
編集済み: LIU 2014 年 1 月 22 日
Probably it's better for me to ask the question with the picture attached here:
Is it possible to adjust the numbers on the axes to be in no more than one digit both before and after decimal point for space saving and avoiding overlapping? Originally, I want the figure to be displayed as follows(it is done by adding text for illustration):
But, I don't know how to make it by coding since there are tens of graphs which would be time-consuming by hand tuning or setting. THank you in advance.

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

回答 (3 件)

Bruno Pop-Stefanov
Bruno Pop-Stefanov 2014 年 1 月 20 日
Please refer to this previous post for formatting tick labels:
  3 件のコメント
Bruno Pop-Stefanov
Bruno Pop-Stefanov 2014 年 1 月 22 日
I did some research and tested myself and apparently, there is no way to control the value of the exponent that MATLAB automatically generates (at least in the current releases).
What you could do instead is label the ticks manually with get and set and play with the exponent:
x = 1:0.1:1000;
y = linspace(-0.005, 0.005, numel(x));
% Find a negative exponent
n = 0;
lpart = floor(max(y));
while lpart == 0
n = n+1;
lpart = floor(10^n * max(y));
end
n = -n;
figure;
plot(x,y)
y_tick = str2num(get(gca, 'YTickLabel'));
set(gca, 'YTickLabel', sprintf('%.e|', y_tick*10^n))
I haven't figured a way to format "0.5e-02" instead of "5.0e-03"... Sorry I can't help you more.
LIU
LIU 2014 年 1 月 22 日
Maybe I should ignore this problem for its hardness, and go ahead.Thank you for your quick response and warm-heartedness,anyway.

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


Walter Roberson
Walter Roberson 2014 年 1 月 20 日
Set yticklabel to the printable representation of the values you want; that will prevent the scale factor from being generated.
  1 件のコメント
LIU
LIU 2014 年 1 月 22 日
編集済み: LIU 2014 年 1 月 22 日
Thank you,Walter. But I didn't mean to prevent the scale factor. Maybe I should explain my question with pictures (see the comment above,please). Hope that helps me ask more clearly.

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


Juan Andrés Martin
Juan Andrés Martin 2020 年 11 月 5 日
編集済み: Walter Roberson 2020 年 11 月 6 日
Refer to "Specify Axis Tick Values and Labels" in Matlab Documentation, specifically "Control Value in Exponent Label Using Ruler Objects" paragraph.
Moreover, using Bruno Pop-Stefanov's code as a basis:
x = 1:0.1:1000;
y = linspace(-0.005, 0.005, numel(x));
plot(x,y)
ax=gca;
ax.YAxis.Exponent=-2;
That should do the trick
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 11 月 6 日
Note that this requires R2015b or newer.
If I recall correctly, there was also a way to do it in R2015a, but the axis property names were different -- YRuler instead of YAxis I think it was.

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

カテゴリ

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