axes tick in scientific notation

71 次查看(过去 30 天)
Wolfgang
Wolfgang 2011-5-23
Hi,
do you know if I can set axes ticks using the scientific notation (i.e. 0.001=1e-3)? The problem is to get the same result if you do 'plot([1:0.1:2]*1e-6)', so that the 'x 10^-6' is outside the tick. 'set(gca, 'ytickLabel',[1:0.1:2]*1e-6)' does not make the same result... How I can reach the same result manually?
  2 个评论
Jan
Jan 2011-5-23
Please explain it again: The "same" result as what? What do you want to appear at the ticks and do you want a common factor to be displayed on top of the axis? "1e-3" is not the "scientific notation", "1e-003" is.
Wolfgang
Wolfgang 2011-5-24
The best for me ist to know how to set the ticks as the example does. So you have the factors at the axis and the 'x 10^-6' above. But I do not know how to manage the 'x 10^-6' that it appears only 1 time and not at every tick entry.

请先登录,再进行评论。

回答(3 个)

Walter Roberson
Walter Roberson 2011-5-24
The scientific notation label will only automatically appear if you have not set the YTickLabel property. If you set YTickLabel, then there is no (documented) way to get MATLAB to automatically put in the exponent the same way.
In order to get around this, if you set YTickLabel and you want the exponent, you need to text() the exponent where you want it to appear.

Arturo Moncada-Torres
Maybe you should check this wonderful tutorial by Loren Shure regarding plots in MATLAB.
  1 个评论
Wolfgang
Wolfgang 2011-5-24
Thanks for the link, but I think it is not very helpfully for me...

请先登录,再进行评论。


Kelly Kearney
Kelly Kearney 2011-5-23
You could try tick2text (or several similar FEX entries):
figure;
plot([1:0.1:2]*1e-6;
tick2text('axis', 'y', 'yformat', '%g', 'ytickoffset', .05);
or for true scientific notation:
fun = @(x) sprintf('%g \\times 10^{%d}', ...
x/(10.^floor(log10(x))), floor(log10(x)));
figure;
plot([1:0.1:2]*1e-6;
tick2text('axis', 'y', 'yformat', fun, 'ytickoffset', .06);
EDIT: To add some text to the axis, rather than to the ticks:
text(0, 1, 'some text', 'horiz', 'left', ...
'vert', 'bottom', ...
'units', 'normalized');
The use of normalized units keeps the text in the same location, even if you change the axis limits. If you want the text to reflect the order of magnitude of the axis limits, you may need to do some of the log10 processing demonstrated above first.
  3 个评论
Kelly Kearney
Kelly Kearney 2011-5-24
Ah, I misunderstood what you were asking for. As Walter suggests, you can manually place text where you need it. Rereading your example, I'm still not quite sure how you want the ticks themselves to appear, but I've modified my answer above to also show how to add some text; modify to suit you purposes.
Oleg Komarov
Oleg Komarov 2011-5-24
I suggest 1.01 for the y coordinate of the text.

请先登录,再进行评论。

类别

Help CenterFile 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!

Translated by