Skip to content

adds rcParam axes.formatter.useoffset #2401

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 1 commit into from
Nov 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions doc/api/api_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ original location:
(n, 1) arrays were returend unchanged. This change makes the dimensions
consistent in both cases.

* Added the rcParam `axes.fromatter.useoffset` to control the default value
of `useOffset` in `ticker.ScalarFormatter`




.. _changes_in_1_3:

Expand Down
16 changes: 12 additions & 4 deletions doc/users/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ New plotting features
Support for datetime axes in 2d plots
`````````````````````````````````````
Andrew Dawson added support for datetime axes to
:func:`~matplotlib.pyplot.contour`, :func:`~matplotlib.pyplot.contourf`,
:func:`~matplotlib.pyplot.pcolormesh` and :func:`~matplotlib.pyplot.pcolor`.
:func:`~matplotlib.pyplot.contour`, :func:`~matplotlib.pyplot.contourf`,
:func:`~matplotlib.pyplot.pcolormesh` and :func:`~matplotlib.pyplot.pcolor`.

Support for additional spectrum types
`````````````````````````````````````
Expand Down Expand Up @@ -83,13 +83,21 @@ conversion interfaces :class:`matplotlib.dates.DateConverter` and

Configuration (rcParams)
------------------------

``savefig.transparent`` added
`````````````````````````````
Controls whether figures are saved with a transparent
Controls whether figures are saved with a transparent
background by default. Previously `savefig` always defaulted
to a non-transparent background.

``axes.formatter.useoffset`` added
``````````````````````````````````
Controls the default value of `useOffset` in `ScalarFormatter`. If
`True` and the data range is much smaller than the data average, then
an offset will be determined such that the tick labels are
meaningful. If `False` then the full number will be formatted in all
conditions.

.. _whats-new-1-3:

new in matplotlib-1.3
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ def __call__(self, s):
'axes.formatter.use_locale': [False, validate_bool],
# Use the current locale to format ticks
'axes.formatter.use_mathtext': [False, validate_bool],
'axes.formatter.useoffset': [True, validate_bool],
'axes.unicode_minus': [True, validate_bool],
'axes.color_cycle': [['b', 'g', 'r', 'c', 'm', 'y', 'k'],
validate_colorlist], # cycle of plot
Expand Down
11 changes: 9 additions & 2 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
unicode_literals)

import six

import nose.tools
from nose.tools import assert_raises
from numpy.testing import assert_almost_equal
import numpy as np

import matplotlib
import matplotlib.ticker as mticker


Expand Down Expand Up @@ -50,6 +50,13 @@ def test_LogLocator():
assert_almost_equal(loc.tick_values(1, 100), test_value)


def test_use_offset():
for use_offset in [True, False]:
with matplotlib.rc_context({'axes.formatter.useoffset': use_offset}):
tmp_form = mticker.ScalarFormatter()
nose.tools.assert_equal(use_offset, tmp_form.get_useOffset())


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
4 changes: 3 additions & 1 deletion lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,13 @@ class ScalarFormatter(Formatter):

"""

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

if useOffset is None:
useOffset = rcParams['axes.formatter.useoffset']
self.set_useOffset(useOffset)
self._usetex = rcParams['text.usetex']
if useMathText is None:
Expand Down
9 changes: 8 additions & 1 deletion matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ backend : %(backend)s
#axes.labelweight : normal # weight of the x and y labels
#axes.labelcolor : black
#axes.axisbelow : False # whether axis gridlines and ticks are below
# the axes elements (lines, text, etc)
# the axes elements (lines, text, etc)

#axes.formatter.limits : -7, 7 # use scientific notation if log10
# of the axis range is smaller than the
# first or larger than the second
Expand All @@ -244,6 +245,12 @@ backend : %(backend)s
# separator in the fr_FR locale.
#axes.formatter.use_mathtext : False # When True, use mathtext for scientific
# 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
# small compared to the minimum absolute
# value of the data.

#axes.unicode_minus : True # use unicode for the minus symbol
# rather than hyphen. See
# http://en.wikipedia.org/wiki/Plus_and_minus_signs#Character_codes
Expand Down