Why does the formatting of my Y-axis tick labels change to exponential format when I plot my data?

15 ビュー (過去 30 日間)
I am plotting x and y data as follows:
x = [1 2 3]
y = [10000 20000 30000]
plot(x,y)
However, once the figure is plotted the Y-axis tick labels are in exponential format 1 ,2 ,3 e+4 . I want the Y-axis tick labels to be in the same format as my original 'y' vector (i.e. 10000, 20000, etc.).

採用された回答

MathWorks Support Team
MathWorks Support Team 2018 年 5 月 17 日
There are two possible workarounds:
1) You can set the Y-ticklabels explicity as follows:
x = [ 1 2 3 ];
y = [10000 20000 30000];
plot(x,y)
set(gca,'YTick',y)
set(gca,'XTick',x)
Yvalues = get(gca,'YTick');
set(gca,'YTickLabel',Yvalues);
2) You could also use the SPRINTF function to format your tick labels using the format of your choice. The 'XTickLabel' or 'YTickLabel' property of the axis would then use those strings as tick labels.
x=[1 2 3];
y=[10000 20000 30000];
plot(x,y)
set(gca,'XTickLabel',sprintf('%3.1f|',x))
set(gca,'XTick',x)
set(gca,'YTickLabel',sprintf('%4.1e|',y))
set(gca,'YTick',y)
For more information on the available formats, consult the documentation for the SPRINTF function:
doc sprintf
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 11 月 28 日
In R2017b you can instead
ax = gca;
ax.YRuler.Exponent = 0;
without setting the labels.
However, this might fail for some log plots.
The above code can also be fixed as,
set(gca,'XTickLabel', sprintfc('%3.1f',x))
set(gca,'YTickLabel', sprintfc('%4.1e',y))

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2007a

Community Treasure Hunt

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

Start Hunting!

Translated by