How can I change the displayed format of exponentials in an axis tick label?
Mostrar comentarios más antiguos
I am preparing a figure for publication that contains diffusion tracks on top of a sample image. I am choosing the color of the tracks based on the track's diffusion coefficient, which ranges from 1e-4 to 1e1 . I would like to put a colorbar below the figure. My current approach is to create the colorbar using meshgrid like so:
aaa = linspace(-4,1,100); [~,Y] = meshgrid(0, aaa); imagesc(Y'); colormap(jet);
I then determine where to put the xticks (its a subplot hence the weirdness) and label them with sprintf:
set(gca,'xtick', [-4:2:0]/.05 + 4/.05 + 1); n=[1e-4 1e-2 1e0]; set(gca,'xticklabel',sprintf('%1.0e |',n), 'ytick', []);
The axis is now labeled in the correct places with the correct numbers, but I wanted the exponentials to be formatted like 10^-4, 10^-2, 10^0 (with big 10 and small superscript exponent) instead of 1e-004 1e-002 1e+000. Is there a way to make this happen? Thanks very much. This forum has been very helpful in the past, this is the first time I have needed to post anything!
Respuestas (1)
Honglei Chen
el 21 de Sept. de 2012
Instead of using
sprintf('%1.0e |',n)
use
sprintf('10^%d |',log10(n))
Categorías
Más información sobre Grid Lines, Tick Values, and Labels en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!