help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

## Re: Exponential notation in tick labels?

 From: Carlo de Falco Subject: Re: Exponential notation in tick labels? Date: Wed, 9 Sep 2009 15:38:16 +0200

```2009/9/9 Carlo de Falco <address@hidden>:
> 2009/9/9 Matthias Brennwald <address@hidden>:
>> Thanks, this does the trick! Now I could even try to adapt this to the
>> "10^n" notation... I don't know a direct way to use sprintf(...) to
>> print numbers in  the 10^n format, but I guess it is feasible by
>> manipulating the ticklabels using string functions somehow.
>
>
> octave-3.2.2:76> x= [1e5:1e5:1e6];
> octave-3.2.2:77> plot(x,x);
> octave-3.2.2:78> axis tight
> octave-3.2.2:79> xt = get(gca, 'xtick');
> octave-3.2.2:80> x_ex = floor(log10(xt));
> octave-3.2.2:81> x_mant = xt./10.^x_ex;
> octave-3.2.2:82> set(gca, 'xticklabel', sprintf('%1.1fx10^{%d}|',
> x_mant, x_ex));
>
>
> Note that if one of the ticks were labeled "0" it would need to be
> handled separately
> (that's the reason for "axis tight")

sorry, I made  mistake in the call to sprintf above..
the approach below should work correctly and also andle the
zeros automatically...

function [ex, mant] = exp_notation (x)
nz = find(x);
ex(nz) = floor(log10(abs(x(nz))));
mant(nz) = x(nz)./10.^ex(nz);
endfunction

octave-3.2.2:108> x= [-1e6:1e5:1e6];
octave-3.2.2:109> plot(x,x);
octave-3.2.2:110> xt = get(gca, 'xtick');[xex,xmant] = exp_notation (xt);
octave-3.2.2:111> yt = get(gca, 'ytick');[yex,ymant] = exp_notation (yt);
octave-3.2.2:112> set(gca, 'xticklabel', sprintf('%3.3gx10^{%d}|',
[xmant; xex](:)));
octave-3.2.2:113> set(gca, 'yticklabel', sprintf('%3.3gx10^{%d}|',
[ymant; yex](:)));

>> Thanks again
>> Matthias
> c.
>

```

reply via email to

 [Prev in Thread] Current Thread [Next in Thread]