8000 ticker.{Eng,Scalar}Formatter: address review comments · matplotlib/matplotlib@e717682 · GitHub
[go: up one dir, main page]

Skip to content

Commit e717682

Browse files
committed
ticker.{Eng,Scalar}Formatter: address review comments
1 parent f651b73 commit e717682

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

doc/users/next_whats_new/EngFormatter-offset.rst

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,25 @@ ticker.EngFormatter now computes offset by default
22
--------------------------------------------------
33

44
``ticker.EngFormatter`` was modified to act very similar to
5-
``ticker.ScalarFormatter``, such that it computes the best offset of the axis
6-
data, and shows the offset with the known SI quantity prefixes. To disable this
7-
new behavior, simply pass ``useOffset=False`` when you instantiate it. If offsets
8-
are disabled, or if there is no particular offset that fits your axis data, the
9-
formatter will revert to the old behavior.
5+
``ticker.ScalarFormatter``, such that it is capable of computing the best
6+
offset of the axis data, and show the offset with the known SI quantity
7+
prefixes.
8+
9+
Since this is a change in behavior, this behavior is disabled by default (in
10+
contrast to the default behavior of ``ScalarFormatter``. To enable it, pass
11+
``useOffset=True`` when you instantiate ``EngFormatter``.
12+
13+
Here's an example result:
14+
15+
.. plot::
16+
17+
import matplotlib.pyplot as plt
18+
import matplotlib.ticker as mticker
19+
20+
fig, ax = plt.subplots()
21+
offset = int(1e7)
22+
ydata = range(offset, offset+5)
23+
ax.plot(ydata)
24+
ax.set_yticks(ydata)
25+
ax.yaxis.set_major_formatter(mticker.EngFormatter(useOffset=True, unit="Hz"))
26+
plt.show()

lib/matplotlib/ticker.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ class ScalarFormatter(Formatter):
411411
To enable/disable the use of TeX's math mode for rendering the
412412
numbers in the formatter.
413413
414+
.. versionadded:: 3.10
415+
414416
Notes
415417
-----
416418
In addition to the parameters above, the formatting of scientific vs.
@@ -1370,7 +1372,7 @@ class EngFormatter(ScalarFormatter):
13701372
}
13711373

13721374
def __init__(self, unit="", places=None, sep=" ", *, usetex=None,
1373-
useMathText=None, useOffset=None):
1375+
useMathText=None, useOffset=False):
13741376
r"""
13751377
Parameters
13761378
----------
@@ -1404,8 +1406,12 @@ def __init__(self, unit="", places=None, sep=" ", *, usetex=None,
14041406
useMathText : bool, default: :rc:`axes.formatter.use_mathtext`
14051407
To enable/disable the use mathtext for rendering the numbers in
14061408
the formatter.
1407-
useOffset : bool or float, default: :rc:`axes.formatter.useoffset`
1409+
useOffset : bool or float, default: False
14081410
Whether to use offset notation. See `.set_useOffset`.
1411+
Passing None will make it default to the value of
1412+
:rc:`axes.formatter.useoffset`
1413+
1414+
.. versionadded:: 3.10
14091415
"""
14101416
self.unit = unit
14111417
self.places = places

0 commit comments

Comments
 (0)
0