How can I change the displayed format of exponentials in an axis tick label?

1 view (last 30 days)
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!

Answers (1)

Honglei Chen
Honglei Chen on 21 Sep 2012
Instead of using
sprintf('%1.0e |',n)
use
sprintf('10^%d |',log10(n))

Products

Community Treasure Hunt

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

Start Hunting!