I have an axis with tick labels and I want them all to have 3.1 format. For example, I do a plot (1:5) and I change my tick labels using the command
set(gca, 'XTick', [1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0])
However, they appear as:
[1 1.5 2 2.5 3 3.5 4 4.5 5]
I would like to get them to appear as I typed them in the above command.
Also, I want to know if it is possible to specify the format of the plot axes tick label which is automatically placed by MATLAB.

 Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 7 Aug. 2017

0 Stimmen

To change the format of the tick labels, use the xtickformat, ytickformat, and ztickformat functions. For example, this code sets the format to show one decimal value for the labels along the x-axis.
plot(1:10)
xtickformat('%,.1f')
For more information, see the xtickformat function page:
These functions were introduced in R2016b. If you are using R2015b or R2016a, set the TickLabelFormat property instead. For example:
ax = gca;
ax.XAxis.TickLabelFormat = '%,.1f';

Weitere Antworten (0)

Kategorien

Mehr zu Axes Appearance finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2016b

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by