Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Offset and scaling factors in axis format #4376 #6086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Made come more readable and more consistent with matplotlib defaults
  • Loading branch information
VincentVandalon committed Mar 2, 2016
commit 02f0a11397fb89fc57dd904791f616d77ef0b42f
51 changes: 28 additions & 23 deletions 51 lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ class ScalarFormatter(Formatter):
axes.formatter.limits rc parameter.

"""
mode = {'offset' :0,
'scaling' :1,
'none' :2,
}
_currentMode = 2

def __init__(self, useOffset=None, useMathText=None, useLocale=None):
# useOffset allows plotting small data ranges with large offsets: for
Expand All @@ -426,8 +431,8 @@ def __init__(self, useOffset=None, useMathText=None, useLocale=None):
self.set_useOffset(False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it no longer uses the rcparam?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still honors the rcparam, see line 671 and 672. I (probably) should have been clearer about this in the commit message.

_useoffset and get_useOffset() now indicates if the offset has been set by either the user or the algorithm choosing a good offset; It no longer return the same value as the rcParam.

axes.formatter.useoffset = False now disables the automatic algorithm. The user can still manually set an offset
axes.formatter.useoffset = True allows the automatic algorithm to set an offset. The user can still override this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The practice in the rest of the library is that the value of the rcparams are stashed when the artists are created. In part this is so that the rcparams context manager and in part so that we can be sure of when the rcprams are consulted (many things are deffered to draw time).

self.set_useScalingFactor(False)
if rcParams['axes.formatter.useoffset'] == True:
self._offsetScaleNone=0 #Basically an enum: 0=offset 1=scale 2=none
self._offsetScaleNone=2 #Basically an enum: 0=offset 1=scale 2=none
self._currentMode=self.mode['offset']
self._currentMode=self.mode['none']

self._usetex = rcParams['text.usetex']
if useMathText is None:
Expand All @@ -436,14 +441,14 @@ def __init__(self, useOffset=None, useMathText=None, useLocale=None):
self.orderOfMagnitude = 0
self.format = ''
self._scientific = True
self._offsetString = ''
self._offsetString = None
self._powerlimits = rcParams['axes.formatter.limits']
if useLocale is None:
useLocale = rcParams['axes.formatter.use_locale']
self._useLocale = useLocale

def get_useScalingFactor(self):
return self._offsetScaleNone == 1
return self._currentMode == self.mode['scaling']

def set_useScalingFactor(self,val):
"""
Expand All @@ -466,19 +471,19 @@ def set_useScalingFactor(self,val):

if val in [True, False]:
self.orderOfMagnitude=math.log10(1)
self._offsetScaleNone=1 #0=offset 1=scale 2=none
self._currentMode=self.mode['scaling']
if val == False:
self._offsetScaleNone=2 #0=offset 1=scale 2=none
self._currentMode=self.mode['none']
elif isinstance(val,numbers.Number):
self._offsetScaleNone=1 #0=offset 1=scale 2=none
self._currentMode=self.mode['scaling']
self.orderOfMagnitude=.5*math.log10(val*val)
else:
raise ValueError("'val' must be a number or a boolean")

useScalingFactor = property(fget=get_useScalingFactor, fset=set_useScalingFactor)

def get_useOffset(self):
return self._offsetScaleNone == 0
return self._currentMode == self.mode['offset']

def set_useOffset(self, val):
"""
Expand All @@ -500,11 +505,11 @@ def set_useOffset(self, val):
"""
if val in [True, False]:
self.offsetval = 0
self._offsetScaleNone=0 #0=offset 1=scale 2=none
self._currentMode=self.mode['offset']
if val == False:
self._offsetScaleNone=2 #0=offset 1=scale 2=none
self._currentMode=self.mode['none']
elif isinstance(val,numbers.Number):
self._offsetScaleNone=0 #0=offset 1=scale 2=none
self._currentMode=self.mode['offset']
self.offsetval = val
else:
raise ValueError("'val' must be a number or a boolean")
Expand Down Expand Up @@ -597,7 +602,7 @@ def set_offset_string(self,s):
"""
Set the string which typically contains the offset
or the scaling factor which is to be displayed on the axis.
Set this to and empty string "" allows the string set by offset or scaling
Set this to None to allow the string set by offset or scaling
algorithm.

Parameters
Expand Down Expand Up @@ -626,20 +631,20 @@ def get_offset(self):
:string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no : here

"""
#String has been set manually, so just return that
if self._offsetString != '' :
if self._offsetString != None :
return self._offsetString

if len(self.locs) == 0:
return ''
s = ''
offsetStr = ''
sciNotStr = ''
if self._offsetScaleNone == 0: #OFFSET
if self._offsetScaleNone == 0:
if self._currentMode == self.mode['offset']:
if self._currentMode == self.mode['offset']:
offsetStr = self.format_data(self.offsetval)
if self.offsetval > 0:
offsetStr = ' +' + offsetStr
elif self._offsetScaleNone == 1: #SCALE
elif self._currentMode == self.mode['scaling']:
if self.orderOfMagnitude:
if self._usetex or self._useMathText:
sciNotStr = self.format_data(10 ** self.orderOfMagnitude)
Expand Down Expand Up @@ -676,7 +681,7 @@ def set_locs(self, locs):
def _set_offset(self, range):
#Determine if an offset is needed and if so, set it.
#This is only needed when scaling/offset hasn't been set by the user
if self._offsetScaleNone != 2:
if self._currentMode != self.mode['none']:
return

# offset of 20,001 is 20,000, for example
Expand Down Expand Up @@ -707,12 +712,12 @@ def _set_orderOfMagnitude(self, range):
# If the user has set scale/offset, their input is used
# if scientific notation is to be used, find the appropriate exponent
# if using an numerical offset, find the exponent after applying the
if self._offsetScaleNone != 2 or self._scientific == False:
if self._currentMode != self.mode['none'] or self._scientific == False:
#User specified or unwanted
return

locs = np.absolute(self.locs)
if self._offsetScaleNone == 0:
if self._currentMode == self.mode['offset']:
oom = math.floor(math.log10(range))
else:
if locs[0] > locs[-1]:
Expand All @@ -725,10 +730,10 @@ def _set_orderOfMagnitude(self, range):
oom = math.floor(math.log10(val))
if oom <= self._powerlimits[0]:
self.orderOfMagnitude = oom
self._offsetScaleNone=1 #Set to scale
self._currentMode=self.mode['scaling']
elif oom >= self._powerlimits[1]:
self.orderOfMagnitude = oom
self._offsetScaleNone=1 #Set to scale
self._currentMode=self.mode['scaling']
else:
self.orderOfMagnitude = 0

Expand Down Expand Up @@ -769,9 +774,9 @@ def _set_format(self, vmin, vmax):

def pprint_val(self, x):
#Decide if we are doing offset, scale, or none
if self._offsetScaleNone == 0 :
if self._currentMode == self.mode['offset'] :
xp = x - self.offsetval
elif self._offsetScaleNone == 1:
elif self._currentMode == self.mode['scaling']:
xp = x / (10. ** self.orderOfMagnitude)
else:
xp = x
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.