A minor comment.
John's code may give incorrect results when exponents are negative.
int() truncates a floating point argument towards zero, e.g.,
int(-1.5) == -1  not -2. I guess calling floor() before int() will
work.

       fx = int(np.floor(np.log(abs(val))/np.log(self._base) +0.5))

-JJ


On Mon, Aug 11, 2008 at 3:23 PM, John Hunter <[EMAIL PROTECTED]> wrote:
> On Mon, Aug 11, 2008 at 1:45 PM, Jeffrey Fogel
> <[EMAIL PROTECTED]> wrote:
>
>> The two things I have been unable to figure out are how to add a major
>> tick at all of the other magnitudes (those without a label) and how to
>> change the format of the labels so that only the exponent is showing.
>> I'm sure both of these are straightforward, but I have been unable to
>> figure them out.  Thanks for your help.
>
> You can accomplish both in one swoop using a custom formatter instead
> of a custom locator.  That is, instead of using a
> LogLocator(base=100.0) which isn't giving you ticks where you want
> them, use the default log locator, and make a custom formatter to
> suppress strings where you don't want them and to use the format you
> want.  Eg, something like
>
> import numpy as np
> import matplotlib.pyplot as plt
> import matplotlib.ticker as ticker
>
> fig = plt.figure()
> ax = fig.add_subplot(111)
>
> N = 1000
> x = np.arange(N)
> y = np.random.rand(N)*1e8
>
> ax.semilogy(x, y)
>
> class MyFormatter(ticker.LogFormatter):
>
>    def __call__(self, val, pos=None):
>        fx = int(np.log(abs(val))/np.log(self._base) +0.5)
>        isDecade = self.is_decade(fx)
>        if not isDecade and self.labelOnlyBase:
>            return ''
>        if (fx%2)==1: # odd, skip
>            return ''
>
>        return '%d'%fx
>
>
> ax.yaxis.set_major_formatter(MyFormatter())
> plt.show()
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Matplotlib-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to