fix to a FormatStrFormatter problem

Hello matplotlib people,

I have run into a problem with the default behaviour for formatting the
axis numbers. For some reason they were not being rounded correctly for
me, for example the number on the axis would be of the form 1.6000001
while the offset was 1e-7 + 4.76928. I am not sure why this is, but it
seemed I needed to use the FormatSrtFormatter to fix the numbers in the

The problem I had was that I needed the offset displayed and unlike the
ScalarFormatter, FormatSrtFormatter does not have an option to specify
this. I made a new version of the FormatSrtFormatter by overriding the
call method from ScalarFormatter ..

from matplotlib.ticker import ScalarFormatter
class FormatStrFormatter(ScalarFormatter):
     Use a format string (fmt) to format the tick label, other options
are the same as for ScalarFormatter
    def __init__(self, useOffset=True, useMathText=True, fmt='%1.3f'):
        self.fmt = fmt
        ScalarFormatter.__init__(self, useOffset, useMathText)

    def __call__(self, x, pos=None):
        'Return the format for tick val *x* at position *pos*'
        return self.fmt % ( (x-self.offset)*pow(10,
(-1*self.orderOfMagnitude) ) )

Not sure if this is the best way to do it but it seemed to solve the
problem for me.



Richard Graham