8000 STY: in ScalarFormatter, use offset to save at least 4 digits, not 2 by efiring · Pull Request #7365 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

STY: in ScalarFormatter, use offset to save at least 4 digits, not 2 #7365

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

Merged
merged 3 commits into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
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
add axes.formatter.offset_threshold rcParam: classic is 2, v2.0 is 4
  • Loading branch information
efiring committed Nov 2, 2016
commit 255d4c31028bc1ecbb5267cb8c9aef3f54147b0a
4 changes: 4 additions & 0 deletions lib/matplotlib/mpl-data/stylelib/classic.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ axes.formatter.useoffset : True # If True, the tick label formatter
# to an offset when the data range is very
# small compared to the minimum absolute
# value of the data.
axes.formatter.offset_threshold : 2 # When useoffset is True, the offset
# will be used when it can remove
# at least this number of significant
# digits from tick labels.

axes.unicode_minus : True # use unicode for the minus symbol
# rather than hyphen. See
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,7 @@ def validate_animation_writer_path(p):
# Use the current locale to format ticks
'axes.formatter.use_mathtext': [False, validate_bool],
'axes.formatter.useoffset': [True, validate_bool],
'axes.formatter.offset_threshold': [4, validate_int],
'axes.unicode_minus': [True, validate_bool],
'axes.color_cycle': [
['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728',
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_SymmetricalLogLocator_set_params():
nose.tools.assert_equal(sym.numticks, 8)


@cleanup
@cleanup(style='classic')
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this the default style already?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes for image_comparison, but no for cleanup. It looks to me like that is a bug in cleanup.

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 having dejavu about this and some gordian knot we failed to deal with like 6mo ago....

Copy link
Member Author

Choose a reason for hiding this comment

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

Fortunately, it doesn't seem to matter much. style='classic' is needed two places in test_ticker, and a few more in the specific backend testers. The tests are working as they are. I don't think it is worth spending any time on right now.

def test_ScalarFormatter_offset_value():
fig, ax = plt.subplots()
formatter = ax.get_xaxis().get_major_formatter()
Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ def __init__(self, useOffset=None, useMathText=None, useLocale=None):

if useOffset is None:
useOffset = rcParams['axes.formatter.useoffset']
self._offset_threshold = rcParams['axes.formatter.offset_threshold']
self.set_useOffset(useOffset)
self._usetex = rcParams['text.usetex']
if useMathText is None:
Expand Down Expand Up @@ -689,9 +690,10 @@ def _compute_offset(self):
# are no more than 1 apart at that precision?
oom = 1 + next(oom for oom in itertools.count(oom_max, -1)
if abs_max // 10 ** oom - abs_min // 10 ** oom > 1)
# Only use offset if it saves at least 4 significant digits.
# Only use offset if it saves at least _offset_threshold digits.
n = self._offset_threshold - 1
self.offset = (sign * (abs_max // 10 ** oom) * 10 ** oom
if abs_max // 10 ** oom >= 10**3 # 10**(4-1)
if abs_max // 10 ** oom >= 10**n
else 0)

def _set_orderOfMagnitude(self, range):
Expand Down
7 changes: 5 additions & 2 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,13 @@ backend : $TEMPLATE_BACKEND
# notation.
#axes.formatter.useoffset : True # If True, the tick label formatter
# will default to labeling ticks relative
# to an offset when the data range is very
# to an offset when the data range is
# small compared to the minimum absolute
# value of the data.

#axes.formatter.offset_threshold : 4 # When useoffset is True, the offset
# will be used when it can remove
# at least this number of significant
# digits from tick labels.

#axes.unicode_minus : True # use unicode for the minus symbol
# rather than hyphen. See
Expand Down
0