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
>
>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users