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
Allowed both multiplication and scaling again
  • Loading branch information
VincentVandalon committed Mar 6, 2016
commit 53ed61841ef9e907fe041d3714dcde9761cf59ac
78 changes: 32 additions & 46 deletions 78 lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@ class ScalarFormatter(Formatter):
axes.formatter.limits rc parameter.

"""
mode = {'offset': 0, 'scaling': 1, 'none': 2, }
_currentMode = 2
_usingOffset = False
_usingScaling = False
Copy link
Member

Choose a reason for hiding this comment

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

Why class level attributes?

Copy link
Author

Choose a reason for hiding this comment

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

Changed to instance variable / data attributes.


def __init__(self, useOffset=None, useMathText=None, useLocale=None):
# useOffset allows plotting small data ranges with large offsets: for
Expand All @@ -427,7 +427,6 @@ 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)
self._currentMode = self.mode['none']

self._usetex = rcParams['text.usetex']
if useMathText is None:
Expand All @@ -443,7 +442,7 @@ def __init__(self, useOffset=None, useMathText=None, useLocale=None):
self._useLocale = useLocale

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

def set_useScalingFactor(self, val):
"""
Expand All @@ -464,13 +463,11 @@ def set_useScalingFactor(self, val):
NONE
"""

if val in [True, False]:
self.orderOfMagnitude = math.log10(1)
self._currentMode = self.mode['scaling']
if val is False:
self._currentMode = self.mode['none']
if isinstance(val,bool):
self.orderOfMagnitude = 0
self._usingScaling = val
elif isinstance(val, numbers.Number):
self._currentMode = self.mode['scaling']
self._usingScaling = True
self.orderOfMagnitude = .5*math.log10(val*val)
else:
raise ValueError("'val' must be a number or a boolean")
Expand All @@ -479,7 +476,7 @@ def set_useScalingFactor(self, val):
fset=set_useScalingFactor)

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

def set_useOffset(self, val):
"""
Expand All @@ -499,14 +496,13 @@ def set_useOffset(self, val):
-------
NONE
"""
if val in [True, False]:
if isinstance(val, bool):
self.offsetval = 0
self._currentMode = self.mode['offset']
if val is False:
self._currentMode = self.mode['none']
self._usingOffset = val
elif isinstance(val, numbers.Number):
self._currentMode = self.mode['offset']
self._usingOffset = True
self.offsetval = val
print(val)
else:
raise ValueError("'val' must be a number or a boolean")

Expand Down Expand Up @@ -633,19 +629,16 @@ def get_offset(self):
s = ''
offsetStr = ''
sciNotStr = ''
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._currentMode == self.mode['scaling']:
if self.orderOfMagnitude:
if self._usetex or self._useMathText:
sciNotStr = self.format_data(10 ** self.orderOfMagnitude)
else:
# sciNotStr = '%g' % 10 **self.orderOfMagnitude
sciNotStr = ('\u2A2F ' + self.format_data(
10 ** self.orderOfMagnitude))
if self.get_useOffset() is True:
Copy link
Member

Choose a reason for hiding this comment

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

I am assuming that there is a latch someplace that sets this to False if self.offsetval == 0?

offsetStr = self.format_data(self.offsetval)
offsetStr = ' +' + offsetStr
if self.get_useScalingFactor() is True:
if self._usetex or self._useMathText:
sciNotStr = self.format_data(10 ** self.orderOfMagnitude)
else:
# sciNotStr = '%g' % 10 **self.orderOfMagnitude
sciNotStr = ('\u2A2F ' + self.format_data(
Copy link
Member

Choose a reason for hiding this comment

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

I do not know enough about unicode, how common is this code-point?

Copy link
Member

Choose a reason for hiding this comment

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

Should probably use '\times' like we do below?

10 ** self.orderOfMagnitude))

# Do final formatting
if self._useMathText:
Expand Down Expand Up @@ -675,10 +668,10 @@ def set_locs(self, locs):

def _set_offset(self, range):
# Determine if an offset is needed and if so, set it.
# Don't do this if scaling/offset has been set of it is
# Don't do this if offset has already been set of it is
# rcParams forbids automatic offset
if (self._currentMode != self.mode['none'] or
rcParams['axes.formatter.useoffset'] is False) :
if(rcParams['axes.formatter.useoffset'] is False or
Copy link
Member

Choose a reason for hiding this comment

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

This also prevents overriding the rcparam?

self.get_useOffset() is True):
Copy link
Member

Choose a reason for hiding this comment

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

Does this get invalidated someplace on scale change?

return

# offset of 20,001 is 20,000, for example
Expand Down Expand Up @@ -708,12 +701,13 @@ 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._currentMode != self.mode['none'] or self._scientific is False:
# User specified or unwanted

# User specified or unwanted
if self.get_useScalingFactor() is True:
Copy link
Author

Choose a reason for hiding this comment

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

Due to grouping methods (user, inherited, local), the diff is somewhat hard to read.

return

locs = np.absolute(self.locs)
if self._currentMode == self.mode['offset']:
if self._usingOffset == True:
oom = math.floor(math.log10(range))
else:
if locs[0] > locs[-1]:
Expand All @@ -725,11 +719,9 @@ def _set_orderOfMagnitude(self, range):
else:
oom = math.floor(math.log10(val))
if oom <= self._powerlimits[0]:
self.orderOfMagnitude = oom
self._currentMode = self.mode['scaling']
self.set_useScalingFactor(10**oom)
elif oom >= self._powerlimits[1]:
self.orderOfMagnitude = oom
self._currentMode = self.mode['scaling']
self.set_useScalingFactor(10**oom)
else:
self.orderOfMagnitude = 0

Expand Down Expand Up @@ -770,13 +762,7 @@ def _set_format(self, vmin, vmax):
self.format = '$%s$' % _mathdefault(self.format)

def pprint_val(self, x):
# Decide if we are doing offset, scale, or none
if self._currentMode == self.mode['offset']:
xp = x - self.offsetval
elif self._currentMode == self.mode['scaling']:
xp = x / (10. ** self.orderOfMagnitude)
else:
xp = x
xp = (x - self.offsetval) / (10. ** self.orderOfMagnitude)

if np.absolute(xp) < 1e-8:
xp = 0
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.