@@ -274,7 +274,7 @@ class ScalarFormatter(Formatter):
274274 def __init__ (self , useOffset = True , useMathText = False ):
275275 # useOffset allows plotting small data ranges with large offsets:
276276 # for example: [1+1e-9,1+2e-9,1+3e-9]
277- # useMathText will render the offset an scientific notation in mathtext
277+ # useMathText will render the offset and scientific notation in mathtext
278278 self ._useOffset = useOffset
279279 self ._usetex = rcParams ['text.usetex' ]
280280 self ._useMathText = useMathText
@@ -292,7 +292,9 @@ def __call__(self, x, pos=None):
292292 return self .pprint_val (x )
293293
294294 def set_scientific (self , b ):
295- 'True or False to turn scientific notation on or off; see also set_powerlimits()'
295+ '''True or False to turn scientific notation on or off
296+ see also set_powerlimits()
297+ '''
296298 self ._scientific = bool (b )
297299
298300 def set_powerlimits (self , lims ):
@@ -311,11 +313,9 @@ def format_data_short(self,value):
311313 'return a short formatted string representation of a number'
312314 return '%1.3g' % value
313315
314- def format_data (self ,value , sign = False , mathtext = False ):
316+ def format_data (self ,value ):
315317 'return a formatted string representation of a number'
316- if sign : s = '%+1.10e' % value
317- else : s = '%1.10e' % value
318- return self ._formatSciNotation (s ,mathtext = mathtext )
318+ return self ._formatSciNotation ('%1.10e' % value )
319319
320320 def get_offset (self ):
321321 """Return scientific notation, plus offset"""
@@ -324,16 +324,15 @@ def get_offset(self):
324324 offsetStr = ''
325325 sciNotStr = ''
326326 if self .offset :
327- if self ._usetex or self ._useMathText :
328- offsetStr = self .format_data (self .offset , sign = True , mathtext = True )
329- else :
330- offsetStr = self .format_data (self .offset , sign = True , mathtext = False )
327+ offsetStr = self .format_data (self .offset )
328+ if self .offset > 0 : offsetStr = '+' + offsetStr
331329 if self .orderOfMagnitude :
332330 if self ._usetex or self ._useMathText :
333- sciNotStr = r'{\times}' + self .format_data (10 ** self .orderOfMagnitude , mathtext = True )
331+ sciNotStr = r'{\times}' + self .format_data (10 ** self .orderOfMagnitude )
334332 else :
335- sciNotStr = 'x1e%+d' % self .orderOfMagnitude
336- if self ._useMathText or self ._usetex : return '' .join (('$' ,sciNotStr ,offsetStr ,'$' ))
333+ sciNotStr = u'\xd7 ' + '1e%d' % self .orderOfMagnitude
334+ if self ._useMathText or self ._usetex :
335+ return '' .join (('$' ,sciNotStr ,offsetStr ,'$' ))
337336 else : return '' .join ((sciNotStr ,offsetStr ))
338337 else : return ''
339338
@@ -402,14 +401,14 @@ def pprint_val(self, x):
402401 if absolute (xp ) < 1e-8 : xp = 0
403402 return self .format % xp
404403
405- def _formatSciNotation (self , s , mathtext = False ):
404+ def _formatSciNotation (self , s ):
406405 # transform 1e+004 into 1e4, for example
407406 tup = s .split ('e' )
408407 try :
409408 significand = tup [0 ].rstrip ('0' ).rstrip ('.' )
410409 sign = tup [1 ][0 ].replace ('+' , '' )
411410 exponent = tup [1 ][1 :].lstrip ('0' )
412- if mathtext :
411+ if self . _useMathText or self . _usetex :
413412 if significand == '1' :
414413 # reformat 1x10^y as 10^y
415414 significand = ''
0 commit comments