axis number presentation

I am a new user to matplotlib, .. it's great.

One thing I cannot work out is the axis number presentation.
Cannot find any documentation about how to control the presentation of the axis number.

Currently using the default TKAgg plotting GUI backend.

It seems the axis will show up to 3 digits, then switch to Scientific notation. (10, 100, 1e3, 1e4, 1e5 etc)
However I would prefer it would present in enginering notation (10, 100, 1e3, 10e3, 100e3, 1e6, 10e6 ...etc)

While I could handle some of this scaling before plotting (make numbers in the Milli-Seconds range), it becomes non-intutive when I zoom in on details (in the Nano-Second range), and the number becomes 1.23e-4 of a milli sec.

I'd prefer to just plot Seconds, and let Matplotlib scale the number to one of mS, uS, nS, as appropriate for the graph range, and zoom level.

Is this outside the scope of the supplied GUI widget?

Do I need to start thinking of using the plot widget directly, create my own GUI interface, and writing code to handle the scaling of axis in the way I like?

Thanks
Steve

One thing I cannot work out is the axis number presentation.
Cannot find any documentation about how to control the presentation of
the axis number.

Poke around ticker.formatter

However I would prefer it would present in enginering notation (10, 100,
1e3, 10e3, 100e3, 1e6, 10e6 ...etc)

The easiest is to define your own formatter. Please try the solution below.
You can use it as:
gca().xaxis.set_major_formatter(EngrFormatter(3))

···

#####
-------------------------------------------------------------------------
#---- --- Formatters ---
#####
-------------------------------------------------------------------------
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, mrange):
        """Sets the order of margnitude."""
        ScalarFormatter._set_orderOfMagnitude(self, mrange)
        self.orderOfMagnitude = 3*(self.orderOfMagnitude//3)
    #........................
    def _set_format(self):
        """Sets the format string to format all ticklabels."""
        # set the format string to format all the ticklabels
        locs = (N.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

Thank you Pierre,

I've taken a while to get around to it, but this code worked a treat, and taught me a little about how I can override things in matplotlib

Thanks
Steve

Pierre GM wrote:

···

One thing I cannot work out is the axis number presentation.
Cannot find any documentation about how to control the presentation of
the axis number.
    
Poke around ticker.formatter

However I would prefer it would present in enginering notation (10, 100,
1e3, 10e3, 100e3, 1e6, 10e6 ...etc)
    
The easiest is to define your own formatter. Please try the solution below. You can use it as:
gca().xaxis.set_major_formatter(EngrFormatter(3))

##### -------------------------------------------------------------------------
#---- --- Formatters ---
##### -------------------------------------------------------------------------
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, mrange):
        """Sets the order of margnitude."""
        ScalarFormatter._set_orderOfMagnitude(self, mrange)
        self.orderOfMagnitude = 3*(self.orderOfMagnitude//3)
    #........................
    def _set_format(self):
        """Sets the format string to format all ticklabels."""
        # set the format string to format all the ticklabels
        locs = (N.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

Glad you found it useful.
playing some more about it, I realized that there could be some improvement
with small values between 0.001 and 1: the following modifications should
take care of that:

    def _set_orderOfMagnitude(self, mrange):
        """Sets the order of margnitude."""
        locs = N.absolute(self.locs)
        if self.offset:
            oom = math.floor(math.log10(mrange))
        else:
            if locs[0] > locs[-1]:
                val = locs[0]
            else:
                val = locs[-1]
            if val == 0:
                oom = 0
            else:
                oom = math.floor(math.log10(val))
        if oom <= -3:
            self.orderOfMagnitude = 3*(oom//3)
        elif oom <= -1:
            self.orderOfMagnitude = -3
        elif oom >= 4:
            self.orderOfMagnitude = 3*(oom//3)
        else:
            self.orderOfMagnitude = 0

···

On Tuesday 21 November 2006 22:09, Stephen George wrote:

Thank you Pierre,

I've taken a while to get around to it, but this code worked a treat,
and taught me a little about how I can override things in matplotlib