How can I prevent scientific notation on my axes in MATLAB R2015b and later?

484 ビュー (過去 30 日間)
I would like to change the tick labels of my plot so they do not display in scientific notation. 
If I use the "xticklabel" function to manually change the labels, they do not update automatically when I zoom or pan. How can I change the format of my tick labels in a way that is respected by zoom and pan?
 

採用された回答

MathWorks Support Team
MathWorks Support Team 2024 年 9 月 5 日
編集済み: MathWorks Support Team 2024 年 9 月 5 日
Starting in MATLAB R2015b, you can use axis ruler properties to customize the appearance of an individual axis. Please refer to the following examples for how you can remove scientific notation from your axis labels, in a way which is respected by zoom and pan.
In MATLAB R2016b and later:
>> h = plot(1:1000000, 1:1000000) >> ax = ancestor(h, 'axes') >> ax.XAxis.Exponent = 0 >> xtickformat('%.0f')
Setting the "Exponent" property of an axis to 0 removes the exponential notation common to all tick values.
The functions "xtickformat", "ytickformat", and "ztickformat" can then be used to customize the format of your tick labels. In this example, the format is set to fixed-point notation with zero decimal places, which removes the scientific notation from the individual tick labels. The following documentation page describes how to call the "xtickformat" function, and the additional formatting options which are available:
In MATLAB R2015b and R2016a:
>> h = plot(1:1000000, 1:1000000) >> ax = ancestor(h, 'axes') >> ax.XAxis.Exponent = 0 >> ax.XAxis.TickLabelFormat = '%.0f'
In releases R2015b and R2016a, you can use the "TickLabelFormat" property of an axis to customize the format of your labels.
For more information, run the following command on the MATLAB command window to access the documentation page:
web(fullfile(docroot, 'matlab/ref/matlab.graphics.axis.decorator.numericruler-properties.html'))
Please follow the below link to search for the required information regarding the current release:
  4 件のコメント
Walter Roberson
Walter Roberson 2021 年 1 月 4 日
I do not know why that is happening, but a workaround is
ax.XAxis.TickLabels = compose('%g', ax.XAxis.TickValues)
Walter Roberson
Walter Roberson 2022 年 1 月 13 日
Please be more specific about what is not working for you -- and also about which MATLAB release you are using.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by