3 questions about tick labels for large values

Folks,
I need your wisdom about ticks labels on ordinates for large numbers (>1e4).
The default behavior I have (0.87.4) is to display tick labels as "%.1f", and
write a string "x1e+..." above the top left corner of the current axes.

- When using "yaxis.tick_right()", the "x1e..." string stays above the top
left corner. That becomes an issue when using two different scales. How could
I force the 'mantissa' string to be on the same side as the axis it depends
on ?

- How could I change the number of decimals being displayed (for example,
"%.3f" instead of "%.1f"), while keeping the mantissa string ? (I tried a
"FormatStrFormatter("%.3f"), it's not what I want. With "Funcformatter(lambda
x,pos: "%.3f"%(x/1000)))", I lose the mantissa string...)

- Personally, I'm not keen on "3.0 x1e+4", I prefer "30 x1e+3". Is there a way
to get that ?

I guess that with a bit of trial/error with FuncFormatter and fig.text, I
should be able to get what I want, but I wanted to check whether there was
some easier solutions.

Thanks in advance for your help

P.

Hello, um..., P.,

Folks,
I need your wisdom about ticks labels on ordinates for large numbers
(>1e4). The default behavior I have (0.87.4) is to display tick labels as
"%.1f", and write a string "x1e+..." above the top left corner of the
current axes.

- When using "yaxis.tick_right()", the "x1e..." string stays above the top
left corner. That becomes an issue when using two different scales. How
could I force the 'mantissa' string to be on the same side as the axis it
depends on ?

I'll take care of this, but I will need a few days.

- How could I change the number of decimals being displayed (for example,
"%.3f" instead of "%.1f"), while keeping the mantissa string ? (I tried a
"FormatStrFormatter("%.3f"), it's not what I want. With
"Funcformatter(lambda x,pos: "%.3f"%(x/1000)))", I lose the mantissa
string...)

You can write your own custom formatter to do this. You can use
ticker.ScalarFormatter as a guide.

- Personally, I'm not keen on "3.0 x1e+4", I prefer "30 x1e+3". Is there a
way to get that ?

Again, this could be handled by a custom formatter.

I guess that with a bit of trial/error with FuncFormatter and fig.text, I
should be able to get what I want, but I wanted to check whether there was
some easier solutions.

Darren

···

On Wednesday 12 July 2006 03:43, PGM wrote:

As of svn 2560, the label will render over the left or right y-axis depending
on the position of the ticks.

Darren

···

On Wednesday 12 July 2006 09:49, Darren Dale wrote:

Hello, um..., P.,

On Wednesday 12 July 2006 03:43, PGM wrote:
> Folks,
> I need your wisdom about ticks labels on ordinates for large numbers
> (>1e4). The default behavior I have (0.87.4) is to display tick labels as
> "%.1f", and write a string "x1e+..." above the top left corner of the
> current axes.
>
> - When using "yaxis.tick_right()", the "x1e..." string stays above the
> top left corner. That becomes an issue when using two different scales.
> How could I force the 'mantissa' string to be on the same side as the
> axis it depends on ?

I'll take care of this, but I will need a few days.

Darren,

As of svn 2560, the label will render over the left or right y-axis
depending on the position of the ticks.

Sweet ! Thanks a lot !

And following your advice, I came up with the following solution to my problem
(forcing the mantissa to multiple of 3, with a given number of decimals).
Should I post it on the wiki ?

Cheers, and thx again
Pierre

···

#------------------------------------------------------------------------------
class EngrFormatter(ScalarFormatter):
    """A variation of the standard ScalarFormatter, using only multiples of
three in the mantissa. A fixed number of decimals can be displayed with the
optional parameter `ndec` . If `ndec` is None (default), the number of
decimals is defined from the current ticks.
    """
    def __init__(self, ndec=None, useOffset=True, useMathText=False):
        ScalarFormatter.__init__(self, useOffset, useMathText)
        if ndec is None or ndec < 0:
            self.format = None
        elif ndec == 0:
            self.format = "%d"
        else:
            self.format = "%%1.%if" % ndec

    def _set_orderOfMagnitude(self,range):
        ScalarFormatter._set_orderOfMagnitude(self,range)
        self.orderOfMagnitude = 3*(self.orderOfMagnitude//3)

    def _set_format(self):
        # set the format string to format all the ticklabels
        locs = (array(self.locs)-self.offset) /
10**self.orderOfMagnitude+1e-15
        sigfigs = [len(str('%1.3f'% loc).split('.')[1].rstrip('0')) \
                   for loc in locs]
        sigfigs.sort()
        if self.format is None:
            self.format = '%1.' + str(sigfigs[-1]) + 'f'
        if self._usetex or self._useMathText: self.format = '$%s$'%self.format