How do I format tick labels after R2016b?

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.

 Accepted Answer

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';

More Answers (0)

Products

Release

R2016b

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!