axes tick in scientific notation

47 visualizzazioni (ultimi 30 giorni)
Wolfgang
Wolfgang il 23 Mag 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 Commenti
Jan
Jan il 23 Mag 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 il 24 Mag 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.

Accedi per commentare.

Risposte (3)

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

Accedi per commentare.


Kelly Kearney
Kelly Kearney il 23 Mag 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 Commenti
Kelly Kearney
Kelly Kearney il 24 Mag 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 il 24 Mag 2011
I suggest 1.01 for the y coordinate of the text.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by