help with a custom formatter

I would like a custom formatter that does 3 things:

1) Blanks out all the values less than 0.
2) Chooses appropriate major ticks when zoomed out.
3) Shows an integer when the zoom scale is revealing multiple
integers, but shows a decimal number when it is just showing within
one integer; i.e. if it is 1, 2, 3, 4 in first case but 1.1, 1.2,
1.3, 1.4 in the second.

So far I have needs (1) and (2) of this with this super-simple custom formatter:

class MyFormatter(ScalarFormatter):
    def __call__(self, val, pos=None):
        if val < 0:
            return ''
        else:
            return int(val)

But how can I get need (3)? I need to know what the view_interval is
to set a rule for this. Something like:

if view_interval < 1:
    return val #this will be a decimal number
else:
    return int(val) #an integer

So how do I get the view_interval? I'm not understanding how to get
that from matplotlib.ticker.TickHelper()--if that is even the right
way to do it--because get_view_interval() is not a method of
TickHelper but of "DummyAxis", and at that point I've lost the idea.

Any help is appreciated. Thanks,
Che

If you're happy with the default formatter behavior (which seems to
match with your #3 requirement), just reuse it.

class MyFormatter(ScalarFormatter):
   def __call__(self, val, pos=None):
       if val < 0:
           return ''
       else:
           return ScalarFormatter.__call__(self, val)

-JJ

···

On Fri, Feb 12, 2010 at 5:24 PM, C M <cmpython@...287...> wrote:

I would like a custom formatter that does 3 things:

1) Blanks out all the values less than 0.
2) Chooses appropriate major ticks when zoomed out.
3) Shows an integer when the zoom scale is revealing multiple
integers, but shows a decimal number when it is just showing within
one integer; i.e. if it is 1, 2, 3, 4 in first case but 1.1, 1.2,
1.3, 1.4 in the second.

So far I have needs (1) and (2) of this with this super-simple custom formatter:

class MyFormatter(ScalarFormatter):
def __call__(self, val, pos=None):
if val < 0:
return ''
else:
return int(val)

But how can I get need (3)? I need to know what the view_interval is
to set a rule for this. Something like:

if view_interval < 1:
return val #this will be a decimal number
else:
return int(val) #an integer

So how do I get the view_interval? I'm not understanding how to get
that from matplotlib.ticker.TickHelper()--if that is even the right
way to do it--because get_view_interval() is not a method of
TickHelper but of "DummyAxis", and at that point I've lost the idea.

Any help is appreciated. Thanks,
Che

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Thank you very much. That is so simple and works beautifully.

Che

···

On Sat, Feb 13, 2010 at 3:00 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote:

If you're happy with the default formatter behavior (which seems to
match with your #3 requirement), just reuse it.

class MyFormatter(ScalarFormatter):
def __call__(self, val, pos=None):
if val < 0:
return ''
else:
return ScalarFormatter.__call__(self, val)

-JJ