axes tick in scientific notation

37 vues (au cours des 30 derniers jours)
Wolfgang
Wolfgang le 23 Mai 2011
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 commentaires
Jan
Jan le 23 Mai 2011
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 le 24 Mai 2011
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.

Connectez-vous pour commenter.

Réponses (3)

Walter Roberson
Walter Roberson le 24 Mai 2011
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 le 23 Mai 2011
Maybe you should check this wonderful tutorial by Loren Shure regarding plots in MATLAB.
  1 commentaire
Wolfgang
Wolfgang le 24 Mai 2011
Thanks for the link, but I think it is not very helpfully for me...

Connectez-vous pour commenter.


Kelly Kearney
Kelly Kearney le 23 Mai 2011
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 commentaires
Kelly Kearney
Kelly Kearney le 24 Mai 2011
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 le 24 Mai 2011
I suggest 1.01 for the y coordinate of the text.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by