How can I make my tick labels include 4 decimal places
Mostrar comentarios más antiguos
I am trying to make a map over a very small area and three decimals is not enough to distinguish between longitude tick labels on my x axis. How can I tell it to include for decimals on that axis? It automatically includes 4 for my y axis.
figure
imagesc(AN(dlatlim,dlonlim))
set(gca,'Xtick',1:400:length(x_label2),'XTickLabel',x_label(1:400:length(x_label2)));
set(gca,'Ytick',1:400:length(y_label2),'YTickLabel',y_label(1:400:length(y_label2)));
set(gca,'fontsize',16)
Respuestas (1)
Walter Roberson
el 9 de Nov. de 2020
ax = gca;
ax.XAxis.TickLabelFormat = '%.4g';
10 comentarios
Heidi Hirsh
el 9 de Nov. de 2020
Walter Roberson
el 9 de Nov. de 2020
Ah, I see you are using the ticklabels to lie to the user about what the underlying data is. The underlying data is integer -- we can tell from the XTick values.
Anyhow, in your case, you need to adjust how you generate the xlabel and ylabel arrays, and setting the TickLabelFormat is not going to help you.
Have you considered using XData and YData properties with imagesc so as to draw the image in the correct data locations so that you would not have to generate the labels yourself, and so that data cursor would work correctly ?
Heidi Hirsh
el 9 de Nov. de 2020
Editada: Walter Roberson
el 9 de Nov. de 2020
Walter Roberson
el 9 de Nov. de 2020
fig = figure;
ax = axes('Parent', fig)
imagesc(ax, x_label(dlonlim), y_label(dlatlim), AN(dlatlim,dlonlim));
ax.XAxis.TickLabelFormat = '%.4g';
ax.YAxis.TickLabelFormat = '%.4g';
Heidi Hirsh
el 10 de Nov. de 2020
Walter Roberson
el 10 de Nov. de 2020
%.4f will give exactly 4 decimal places
Walter Roberson
el 10 de Nov. de 2020
xtick(x_label2(1:400:end))
Heidi Hirsh
el 10 de Nov. de 2020
Heidi Hirsh
el 10 de Nov. de 2020
Walter Roberson
el 10 de Nov. de 2020
Are x_label or y_label sorted in descending order? If so then that imagesc call would flip the image.
But also some image related operations automatically set YDir property to 'reverse'
Categorías
Más información sobre Axis Labels en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!