Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0fe598c

Browse files
committed
API: finish changing axisbg -> facecolor
- change name of first kwarg (third arg) of `_AxesBase.__init__` from 'axisbg' -> 'facecolor'. - added 'axisbg' back at the end of the listed kwargs - add handling from axisbg / facecolor conflicts This adds a minor, but nasty, API wart in that there are now two positional arguements to set the background color of the axes and API wise we are locked into one positional arg. However, if any non-None value is passed for `axisbg` a warning will be raised and this is the `__init__` on a private base class so should have reatively little user exposure.
1 parent 756102c commit 0fe598c

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

examples/pylab_examples/polar_legend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
# force square figure and square axes looks better for polar, IMO
1212
fig = figure(figsize=(8, 8))
13-
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], projection='polar', facecolor='#d5de9c')
13+
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8],
14+
projection='polar', facecolor='#d5de9c')
1415

1516
r = np.arange(0, 3.0, 0.01)
1617
theta = 2*np.pi*r

lib/matplotlib/axes/_base.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,14 @@ def __str__(self):
413413
return "Axes(%g,%g;%gx%g)" % tuple(self._position.bounds)
414414

415415
def __init__(self, fig, rect,
416-
axisbg=None, # defaults to rc axes.facecolor
416+
facecolor=None, # defaults to rc axes.facecolor
417417
frameon=True,
418418
sharex=None, # use Axes instance's xaxis info
419419
sharey=None, # use Axes instance's yaxis info
420420
label='',
421421
xscale=None,
422422
yscale=None,
423+
axisbg=None, # This will be removed eventually
423424
**kwargs
424425
):
425426
"""
@@ -508,13 +509,17 @@ def __init__(self, fig, rect,
508509

509510
# this call may differ for non-sep axes, e.g., polar
510511
self._init_axis()
511-
512-
if axisbg is None:
513-
axisbg = rcParams['axes.facecolor']
514-
else:
512+
if axisbg is not None and facecolor is not None:
513+
raise TypeError('Both axisbg and facecolor are not None. '
514+
'These keywords are aliases, only one maybe '
515+
'provided.')
516+
if axisbg is not None:
515517
cbook.warn_deprecated(
516518
'2.0', name='axisbg', alternative='facecolor')
517-
self._axisbg = axisbg
519+
facecolor = axisbg
520+
if facecolor is None:
521+
facecolor = rcParams['axes.facecolor']
522+
self._axisbg = facecolor
518523
self._frameon = frameon
519524
self._axisbelow = rcParams['axes.axisbelow']
520525

0 commit comments

Comments
 (0)