axes tick in scientific notation

조회 수: 32 (최근 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
Arturo Moncada-Torres 2011년 5월 23일
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에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by