Borrar filtros
Borrar filtros

Change Number of Decimal Places on Y-Axis Tick Labels on Scatter Plot

5 visualizaciones (últimos 30 días)
AmericanExpat26
AmericanExpat26 el 9 de Sept. de 2016
Comentada: Star Strider el 10 de Sept. de 2016
I am producing a series of scatter plots for a scientific publication and I am trying to change the number of decimal places associated with the tick labels on the y-axis, so that it displays 4 at each increment. Lines of code of interest given below.
ylim([-0.4500 -0.4300])
ytix = get(gca,'ytick')
set(gca,'yticklabel',sprintf('%.4f',ytix));
The values of y-axis tick labels are now indeed include the desired 4 decimal places, but when trying to set the new labels, the entire matrix appears at each tick mark, instead of the appropriate single value. A screenshot of the plot is included.
Any help on how to solve the problem of getting only the right displayed at each tick mark would be appreciated.
-AmericanExpat26

Respuestas (1)

Star Strider
Star Strider el 10 de Sept. de 2016
You need to create a cell array for the y-tick labels, and split each into a separate element of the cell array. Add a separate assignment to generate the labels, and then write all but the last label (which is blank) to 'YTickLabel':
ytixlbl = regexp(sprintf('%.4f\n',ytix), '\n', 'split');
set(gca,'yticklabel',ytixlbl(1:end-1))
You can do the same thing with the strsplit function as with the regexp call, but not everyone has strsplit.

Categorías

Más información sobre Scatter Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by