From 0fe598c3a2572a31199003b673585ad1be1b1af4 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 14 Feb 2016 13:44:51 -0500 Subject: [PATCH 1/6] 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. --- examples/pylab_examples/polar_legend.py | 3 ++- lib/matplotlib/axes/_base.py | 17 +++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/examples/pylab_examples/polar_legend.py b/examples/pylab_examples/polar_legend.py index 8bd86f0e5d12..632f2e8bde0f 100755 --- a/examples/pylab_examples/polar_legend.py +++ b/examples/pylab_examples/polar_legend.py @@ -10,7 +10,8 @@ # force square figure and square axes looks better for polar, IMO fig = figure(figsize=(8, 8)) -ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], projection='polar', facecolor='#d5de9c') +ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], + projection='polar', facecolor='#d5de9c') r = np.arange(0, 3.0, 0.01) theta = 2*np.pi*r diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 050aa3c3408f..3b7805d41735 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -413,13 +413,14 @@ def __str__(self): return "Axes(%g,%g;%gx%g)" % tuple(self._position.bounds) def __init__(self, fig, rect, - axisbg=None, # defaults to rc axes.facecolor + facecolor=None, # defaults to rc axes.facecolor frameon=True, sharex=None, # use Axes instance's xaxis info sharey=None, # use Axes instance's yaxis info label='', xscale=None, yscale=None, + axisbg=None, # This will be removed eventually **kwargs ): """ @@ -508,13 +509,17 @@ def __init__(self, fig, rect, # this call may differ for non-sep axes, e.g., polar self._init_axis() - - if axisbg is None: - axisbg = rcParams['axes.facecolor'] - else: + if axisbg is not None and facecolor is not None: + raise TypeError('Both axisbg and facecolor are not None. ' + 'These keywords are aliases, only one maybe ' + 'provided.') + if axisbg is not None: cbook.warn_deprecated( '2.0', name='axisbg', alternative='facecolor') - self._axisbg = axisbg + facecolor = axisbg + if facecolor is None: + facecolor = rcParams['axes.facecolor'] + self._axisbg = facecolor self._frameon = frameon self._axisbelow = rcParams['axes.axisbelow'] From c68af4afa85c57ce608c3e6531741b4c6b87a465 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 14 Feb 2016 14:05:14 -0500 Subject: [PATCH 2/6] MNT: rename internal variable in _AxesBase _axisbg -> _facecolor Finishing the change from axisbg -> facecolor --- lib/matplotlib/axes/_base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 3b7805d41735..11919c89cd13 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -519,7 +519,7 @@ def __init__(self, fig, rect, facecolor = axisbg if facecolor is None: facecolor = rcParams['axes.facecolor'] - self._axisbg = facecolor + self._facecolor = facecolor self._frameon = frameon self._axisbelow = rcParams['axes.axisbelow'] @@ -1058,7 +1058,7 @@ def cla(self): # setting the edgecolor to None self.patch = self.axesPatch = self._gen_axes_patch() self.patch.set_figure(self.figure) - self.patch.set_facecolor(self._axisbg) + self.patch.set_facecolor(self._facecolor) self.patch.set_edgecolor('None') self.patch.set_linewidth(0) self.patch.set_transform(self.transAxes) @@ -2714,7 +2714,7 @@ def set_axis_on(self): @cbook.deprecated('2.0', alternative='get_facecolor') def get_axis_bgcolor(self): """Return the axis background color""" - return self._axisbg + return self._facecolor @cbook.deprecated('2.0', alternative='set_facecolor') def set_axis_bgcolor(self, color): @@ -2727,7 +2727,7 @@ def set_axis_bgcolor(self, color): warnings.warn( "set_axis_bgcolor is deprecated. Use set_facecolor instead.", cbook.mplDeprecation) - self._axisbg = color + self._facecolor = color self.patch.set_facecolor(color) self.stale = True # data limits, ticks, tick labels, and formatting From 43921542b7b1edc40683644a8ecb20ef2fe255f2 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 14 Feb 2016 14:12:21 -0500 Subject: [PATCH 3/6] DOC: change radio button example to use facecolor Use `facecolor` not `axisbg` --- examples/widgets/radio_buttons.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/widgets/radio_buttons.py b/examples/widgets/radio_buttons.py index b3df1454c48a..f993db59bf72 100644 --- a/examples/widgets/radio_buttons.py +++ b/examples/widgets/radio_buttons.py @@ -12,7 +12,7 @@ plt.subplots_adjust(left=0.3) axcolor = 'lightgoldenrodyellow' -rax = plt.axes([0.05, 0.7, 0.15, 0.15], axisbg=axcolor) +rax = plt.axes([0.05, 0.7, 0.15, 0.15], facecolor=axcolor) radio = RadioButtons(rax, ('2 Hz', '4 Hz', '8 Hz')) @@ -23,7 +23,7 @@ def hzfunc(label): plt.draw() radio.on_clicked(hzfunc) -rax = plt.axes([0.05, 0.4, 0.15, 0.15], axisbg=axcolor) +rax = plt.axes([0.05, 0.4, 0.15, 0.15], facecolor=axcolor) radio2 = RadioButtons(rax, ('red', 'blue', 'green')) @@ -32,7 +32,7 @@ def colorfunc(label): plt.draw() radio2.on_clicked(colorfunc) -rax = plt.axes([0.05, 0.1, 0.15, 0.15], axisbg=axcolor) +rax = plt.axes([0.05, 0.1, 0.15, 0.15], facecolor=axcolor) radio3 = RadioButtons(rax, ('-', '--', '-.', 'steps', ':')) From 058eea7cbafe21bc99447a6b09e653ff6b3059f1 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 14 Feb 2016 16:22:09 -0500 Subject: [PATCH 4/6] FIX: fix typo --- lib/matplotlib/axes/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 11919c89cd13..4113a22e6493 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -511,7 +511,7 @@ def __init__(self, fig, rect, self._init_axis() if axisbg is not None and facecolor is not None: raise TypeError('Both axisbg and facecolor are not None. ' - 'These keywords are aliases, only one maybe ' + 'These keywords are aliases, only one may be ' 'provided.') if axisbg is not None: cbook.warn_deprecated( From 9cf717f8407c2971dd6c3859b5379efe9d46e842 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 15 Feb 2016 12:13:27 -0500 Subject: [PATCH 5/6] MNT: simplify deprecation of axis_bg_color - the decorator takes care of the warning - fall back got get/set_facecolor instead of private internal state --- lib/matplotlib/axes/_base.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 4113a22e6493..8e0e8193b5c5 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2714,7 +2714,7 @@ def set_axis_on(self): @cbook.deprecated('2.0', alternative='get_facecolor') def get_axis_bgcolor(self): """Return the axis background color""" - return self._facecolor + return self.get_facecolor() @cbook.deprecated('2.0', alternative='set_facecolor') def set_axis_bgcolor(self, color): @@ -2724,12 +2724,7 @@ def set_axis_bgcolor(self, color): ACCEPTS: any matplotlib color - see :func:`~matplotlib.pyplot.colors` """ - warnings.warn( - "set_axis_bgcolor is deprecated. Use set_facecolor instead.", - cbook.mplDeprecation) - self._facecolor = color - self.patch.set_facecolor(color) - self.stale = True + return self.set_facecolor(color) # data limits, ticks, tick labels, and formatting def invert_xaxis(self): From df3e4bcf0ccd9989b98f3b0f8b51409cca9b820b Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 15 Feb 2016 12:21:09 -0500 Subject: [PATCH 6/6] API: match previous set_axis_bgcolor behavior When setting the facecolor stash the value so that future calls to `cla` will restore the facecolor to this value. --- lib/matplotlib/axes/_base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 8e0e8193b5c5..73075f5bbbd3 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -1088,6 +1088,7 @@ def get_facecolor(self): get_fc = get_facecolor def set_facecolor(self, color): + self._facecolor = color return self.patch.set_facecolor(color) set_fc = set_facecolor