Skip to content

Commit 7897abd

Browse files
committed
Merge pull request #2401 from tacaswell/useoffset_rcparam
adds rcParam `axes.formatter.useoffset`
2 parents 3b5364d + 06a2696 commit 7897abd

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

doc/api/api_changes.rst

+5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ original location:
100100
(n, 1) arrays were returend unchanged. This change makes the dimensions
101101
consistent in both cases.
102102

103+
* Added the rcParam `axes.fromatter.useoffset` to control the default value
104+
of `useOffset` in `ticker.ScalarFormatter`
105+
106+
107+
103108

104109
.. _changes_in_1_3:
105110

doc/users/whats_new.rst

+12-4
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ New plotting features
3535
Support for datetime axes in 2d plots
3636
`````````````````````````````````````
3737
Andrew Dawson added support for datetime axes to
38-
:func:`~matplotlib.pyplot.contour`, :func:`~matplotlib.pyplot.contourf`,
39-
:func:`~matplotlib.pyplot.pcolormesh` and :func:`~matplotlib.pyplot.pcolor`.
38+
:func:`~matplotlib.pyplot.contour`, :func:`~matplotlib.pyplot.contourf`,
39+
:func:`~matplotlib.pyplot.pcolormesh` and :func:`~matplotlib.pyplot.pcolor`.
4040

4141
Support for additional spectrum types
4242
`````````````````````````````````````
@@ -83,13 +83,21 @@ conversion interfaces :class:`matplotlib.dates.DateConverter` and
8383

8484
Configuration (rcParams)
8585
------------------------
86-
86+
8787
``savefig.transparent`` added
8888
`````````````````````````````
89-
Controls whether figures are saved with a transparent
89+
Controls whether figures are saved with a transparent
9090
background by default. Previously `savefig` always defaulted
9191
to a non-transparent background.
9292

93+
``axes.formatter.useoffset`` added
94+
``````````````````````````````````
95+
Controls the default value of `useOffset` in `ScalarFormatter`. If
96+
`True` and the data range is much smaller than the data average, then
97+
an offset will be determined such that the tick labels are
98+
meaningful. If `False` then the full number will be formatted in all
99+
conditions.
100+
93101
.. _whats-new-1-3:
94102

95103
new in matplotlib-1.3

lib/matplotlib/rcsetup.py

+1
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ def __call__(self, s):
592592
'axes.formatter.use_locale': [False, validate_bool],
593593
# Use the current locale to format ticks
594594
'axes.formatter.use_mathtext': [False, validate_bool],
595+
'axes.formatter.useoffset': [True, validate_bool],
595596
'axes.unicode_minus': [True, validate_bool],
596597
'axes.color_cycle': [['b', 'g', 'r', 'c', 'm', 'y', 'k'],
597598
validate_colorlist], # cycle of plot

lib/matplotlib/tests/test_ticker.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
unicode_literals)
33

44
import six
5-
5+
import nose.tools
66
from nose.tools import assert_raises
77
from numpy.testing import assert_almost_equal
88
import numpy as np
9-
9+
import matplotlib
1010
import matplotlib.ticker as mticker
1111

1212

@@ -50,6 +50,13 @@ def test_LogLocator():
5050
assert_almost_equal(loc.tick_values(1, 100), test_value)
5151

5252

53+
def test_use_offset():
54+
for use_offset in [True, False]:
55+
with matplotlib.rc_context({'axes.formatter.useoffset': use_offset}):
56+
tmp_form = mticker.ScalarFormatter()
57+
nose.tools.assert_equal(use_offset, tmp_form.get_useOffset())
58+
59+
5360
if __name__ == '__main__':
5461
import nose
5562
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/ticker.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,13 @@ class ScalarFormatter(Formatter):
356356
357357
"""
358358

359-
def __init__(self, useOffset=True, useMathText=None, useLocale=None):
359+
def __init__(self, useOffset=None, useMathText=None, useLocale=None):
360360
# useOffset allows plotting small data ranges with large offsets: for
361361
# example: [1+1e-9,1+2e-9,1+3e-9] useMathText will render the offset
362362
# and scientific notation in mathtext
363363

364+
if useOffset is None:
365+
useOffset = rcParams['axes.formatter.useoffset']
364366
self.set_useOffset(useOffset)
365367
self._usetex = rcParams['text.usetex']
366368
if useMathText is None:

matplotlibrc.template

+8-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ backend : %(backend)s
234234
#axes.labelweight : normal # weight of the x and y labels
235235
#axes.labelcolor : black
236236
#axes.axisbelow : False # whether axis gridlines and ticks are below
237-
# the axes elements (lines, text, etc)
237+
# the axes elements (lines, text, etc)
238+
238239
#axes.formatter.limits : -7, 7 # use scientific notation if log10
239240
# of the axis range is smaller than the
240241
# first or larger than the second
@@ -244,6 +245,12 @@ backend : %(backend)s
244245
# separator in the fr_FR locale.
245246
#axes.formatter.use_mathtext : False # When True, use mathtext for scientific
246247
# notation.
248+
#axes.formatter.useoffset : True # If True, the tick label formatter
249+
# will default to labeling ticks relative
250+
# to an offset when the data range is very
251+
# small compared to the minimum absolute
252+
# value of the data.
253+
247254
#axes.unicode_minus : True # use unicode for the minus symbol
248255
# rather than hyphen. See
249256
# http://en.wikipedia.org/wiki/Plus_and_minus_signs#Character_codes

0 commit comments

Comments
 (0)