How can I change the displayed format of exponentials in an axis tick label?
이전 댓글 표시
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!
답변 (1개)
Honglei Chen
2012년 9월 21일
Instead of using
sprintf('%1.0e |',n)
use
sprintf('10^%d |',log10(n))
카테고리
도움말 센터 및 File Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!