Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
PEP8 issues
  • Loading branch information
VincentVandalon committed Mar 6, 2016
commit 9ce9d3c3d146132f612bd793a4e7bb534815a397
8 changes: 4 additions & 4 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def set_useScalingFactor(self, val):
NONE
"""

if isinstance(val,bool):
if isinstance(val, bool):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there another way to do this logic? Switching code paths based on the type is a bit of an anti-pattern in python.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I can either change the signature of the set_useOffset() and set_useScalingfactor() to (self, state, val=0). Keeping set_useOffset and set_useScalingfactor identical is preferred I guess? The logic would be much simpeler then, but it would introduce a change in the user API.

Previously code in set_useOffset() was if val in [True, False]:
Setting the offset to 1 would result in an offset of 0 because 1 in [True,False] == True. That's why I added the type check. Let me think about this a bit if it can be done cleaner.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

fair enough. Given the existing API I am convinced that this is the best of the bad options.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This change fixes a real bug. I just hit the annoying case that useOffset=1.0 (even with a floating point 1.0!) does not do anything because

In [10]: 1.0 in [True, False]
Out[10]: True

It would be nice if this could be applied, possibly independent of the other changes proposed in the patch set.

self.orderOfMagnitude = 0
self._usingScaling = val
elif isinstance(val, numbers.Number):
Expand Down Expand Up @@ -668,8 +668,8 @@ 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 offset has already been set of it is
# rcParams forbids automatic offset
# Don't do this if offset has already been set of it is
# rcParams forbids automatic offset
if(rcParams['axes.formatter.useoffset'] is False or

Copy link
Copy Markdown
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
Copy Markdown
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
Expand Down Expand Up @@ -707,7 +707,7 @@ def _set_orderOfMagnitude(self, range):
return

locs = np.absolute(self.locs)
if self._usingOffset == True:
if self.get_useOffset() is True:
oom = math.floor(math.log10(range))
else:
if locs[0] > locs[-1]:
Expand Down