-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Changes from 1 commit
137c7aa
ab1b3a2
4079e1a
bfc7389
09f800c
02f0a11
5368336
fee8ab9
681820f
66061ad
53ed618
4c86635
9ce9d3c
8d9d121
2737c5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
def __init__(self, useOffset=None, useMathText=None, useLocale=None): | ||
# useOffset allows plotting small data ranges with large offsets: for | ||
|
@@ -427,7 +427,6 @@ def __init__(self, useOffset=None, useMathText=None, useLocale=None): | |
|
||
self.set_useOffset(False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it no longer uses the rcparam? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
@@ -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): | ||
""" | ||
|
@@ -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") | ||
|
@@ -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): | ||
""" | ||
|
@@ -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") | ||
|
||
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably use |
||
10 ** self.orderOfMagnitude)) | ||
|
||
# Do final formatting | ||
if self._useMathText: | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also prevents overriding the rcparam? |
||
self.get_useOffset() is True): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]: | ||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why class level attributes?
There was a problem hiding this comment.
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.