Skip to content

Commit 277574f

Browse files
committed
Restore some backcompat.
1 parent 387a34e commit 277574f

File tree

5 files changed

+35
-30
lines changed

5 files changed

+35
-30
lines changed

examples/pylab_examples/demo_ribbon_box.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def draw(self, renderer, *args, **kwargs):
104104
]
105105
heights = np.random.random(years.shape) * 7000 + 3000
106106

107-
fmt = ScalarFormatter(use_offset=False)
107+
fmt = ScalarFormatter(useOffset=False)
108108
ax.xaxis.set_major_formatter(fmt)
109109

110110
for year, h, bc in zip(years, heights, box_colors):

examples/pylab_examples/newscalarformatter_demo.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@
3333
verticalalignment='top')
3434

3535
ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
36-
ax1.xaxis.set_major_formatter(ScalarFormatter(use_offset=False))
37-
ax1.yaxis.set_major_formatter(ScalarFormatter(use_offset=False))
36+
ax1.xaxis.set_major_formatter(ScalarFormatter(useOffset=False))
37+
ax1.yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
3838

3939
ax2.plot(x * 1e5, x * 1e-4)
40-
ax2.xaxis.set_major_formatter(ScalarFormatter(use_offset=False))
41-
ax2.yaxis.set_major_formatter(ScalarFormatter(use_offset=False))
40+
ax2.xaxis.set_major_formatter(ScalarFormatter(useOffset=False))
41+
ax2.yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
4242

4343
ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
44-
ax3.xaxis.set_major_formatter(ScalarFormatter(use_offset=False))
45-
ax3.yaxis.set_major_formatter(ScalarFormatter(use_offset=False))
44+
ax3.xaxis.set_major_formatter(ScalarFormatter(useOffset=False))
45+
ax3.yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
4646

4747
ax4.plot(-x * 1e5, -x * 1e-4)
48-
ax4.xaxis.set_major_formatter(ScalarFormatter(use_offset=False))
49-
ax4.yaxis.set_major_formatter(ScalarFormatter(use_offset=False))
48+
ax4.xaxis.set_major_formatter(ScalarFormatter(useOffset=False))
49+
ax4.yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
5050

5151
# Example 4
5252
x = np.arange(0, 1, .01)
@@ -56,18 +56,18 @@
5656
verticalalignment='top')
5757

5858
ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
59-
ax1.xaxis.set_major_formatter(ScalarFormatter(use_mathtext=True))
60-
ax1.yaxis.set_major_formatter(ScalarFormatter(use_mathtext=True))
59+
ax1.xaxis.set_major_formatter(ScalarFormatter(useMathText=True))
60+
ax1.yaxis.set_major_formatter(ScalarFormatter(useMathText=True))
6161

6262
ax2.plot(x * 1e5, x * 1e-4)
63-
ax2.xaxis.set_major_formatter(ScalarFormatter(use_mathtext=True))
64-
ax2.yaxis.set_major_formatter(ScalarFormatter(use_mathtext=True))
63+
ax2.xaxis.set_major_formatter(ScalarFormatter(useMathText=True))
64+
ax2.yaxis.set_major_formatter(ScalarFormatter(useMathText=True))
6565

6666
ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
67-
ax3.xaxis.set_major_formatter(ScalarFormatter(use_mathtext=True))
68-
ax3.yaxis.set_major_formatter(ScalarFormatter(use_mathtext=True))
67+
ax3.xaxis.set_major_formatter(ScalarFormatter(useMathText=True))
68+
ax3.yaxis.set_major_formatter(ScalarFormatter(useMathText=True))
6969

7070
ax4.plot(-x * 1e5, -x * 1e-4)
71-
ax4.xaxis.set_major_formatter(ScalarFormatter(use_mathtext=True))
72-
ax4.yaxis.set_major_formatter(ScalarFormatter(use_mathtext=True))
71+
ax4.xaxis.set_major_formatter(ScalarFormatter(useMathText=True))
72+
ax4.yaxis.set_major_formatter(ScalarFormatter(useMathText=True))
7373
plt.show()

lib/matplotlib/axes/_base.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ def __init__(self, fig, rect,
523523
self._hold = rcParams['axes.hold']
524524
self._connected = {} # a dict from events to (id, func)
525525
self.cla()
526+
# funcs used to format x and y - fall back on major formatters
527+
self.fmt_xdata = None
528+
self.fmt_ydata = None
526529

527530
self.set_cursor_props((1, 'k')) # set the cursor properties for axes
528531

@@ -3265,10 +3268,12 @@ def yaxis_date(self, tz=None):
32653268
self.yaxis.axis_date(tz)
32663269

32673270
def format_xdata(self, x):
3268-
return self.xaxis.get_major_formatter().format_for_cursor(x)
3271+
return (self.fmt_xdata(x) if self.fmt_xdata is not None
3272+
else self.xaxis.get_major_formatter().format_for_cursor(x))
32693273

32703274
def format_ydata(self, y):
3271-
return self.yaxis.get_major_formatter().format_for_cursor(y)
3275+
return (self.fmt_ydata(y) if self.fmt_ydata is not None
3276+
else self.yaxis.get_major_formatter().format_for_cursor(y))
32723277

32733278
def format_coord(self, x, y):
32743279
"""Return a format string formatting the *x*, *y* coord"""

lib/matplotlib/ticker.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -319,18 +319,14 @@ class ScalarFormatter(Formatter):
319319
axes.formatter.limits rc parameter.
320320
"""
321321

322-
def __init__(self, *args, **kwargs):
323-
# Keyword-only arguments.
324-
use_offset = kwargs.pop("use_offset", None)
325-
use_mathtext = kwargs.pop("use_mathtext", None)
326-
use_locale = kwargs.pop("use_locale", None)
327-
super(ScalarFormatter, self).__init__(*args, **kwargs)
328-
self._use_offset = (use_offset if use_offset is not None
322+
def __init__(self, useOffset=None, useMathText=None, useLocale=None):
323+
super(ScalarFormatter, self).__init__()
324+
self._use_offset = (useOffset if useOffset is not None
329325
else rcParams["axes.formatter.useoffset"])
330326
self._usetex = rcParams["text.usetex"]
331-
self._use_mathtext = (use_mathtext if use_mathtext is not None
327+
self._use_mathtext = (useMathText if useMathText is not None
332328
else rcParams["axes.formatter.use_mathtext"])
333-
self._use_locale = (use_locale if use_locale is not None
329+
self._use_locale = (useLocale if useLocale is not None
334330
else rcParams["axes.formatter.use_locale"])
335331
self._scientific = True
336332
self._powerlimits = rcParams['axes.formatter.limits']
@@ -393,12 +389,15 @@ def _update(self):
393389

394390
def _set_offset(self):
395391
locs = self.locs
396-
if not len(locs) or not self._use_offset:
392+
if not self._use_offset:
397393
self._offset = 0
398394
return
399395
# Restrict to visible ticks.
400396
vmin, vmax = sorted(self.axis.get_view_interval())
401397
locs = locs[(vmin <= locs) & (locs <= vmax)]
398+
if not len(locs):
399+
self._offset = 0
400+
return
402401
lmin, lmax = locs.min(), locs.max()
403402
# min, max comparing absolute values (we want division to round towards
404403
# zero so we work on absolute values).

lib/mpl_toolkits/axisartist/grid_finder.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ def set_factor(self, f):
306306

307307
class FormatterPrettyPrint(object):
308308
def __init__(self, useMathText=True):
309-
self._fmt = mticker.ScalarFormatter(use_mathtext=useMathText, use_offset=False)
309+
self._fmt = mticker.ScalarFormatter(
310+
useMathText=useMathText, useOffset=False)
310311
self._fmt.set_axis({})
311312
self._ignore_factor = True
312313

0 commit comments

Comments
 (0)