diff --git a/doc/api/api_changes.rst b/doc/api/api_changes.rst index 443c08ed445e..119816a18c74 100644 --- a/doc/api/api_changes.rst +++ b/doc/api/api_changes.rst @@ -11,6 +11,15 @@ sources of the changes you are experiencing. For new features that were added to matplotlib, please see :ref:`whats-new`. +Changes in 2.0.0 +================ + +Color of Axes +------------- + +The ``axisbg`` and ``axis_bgcolor`` properties on ``Axes`` have been +deprecated in favor of ``facecolor``. + Changes in 1.5.0 ================ diff --git a/doc/users/plotting/colormaps/Lfunction.py b/doc/users/plotting/colormaps/Lfunction.py index ed64bfb07380..d9a06759ea28 100644 --- a/doc/users/plotting/colormaps/Lfunction.py +++ b/doc/users/plotting/colormaps/Lfunction.py @@ -49,10 +49,10 @@ for i in range(red.shape[1]): # LHS: additive - ax1 = fig.add_subplot(nrows,2,i*2+1, axisbg=tuple(rgb_add[0,i,:])) + ax1 = fig.add_subplot(nrows,2,i*2+1, facecolor=tuple(rgb_add[0,i,:])) # RHS: multiplicative - ax2 = fig.add_subplot(nrows,2,i*2+2, axisbg=tuple(rgb_geometric[0,i,:])) + ax2 = fig.add_subplot(nrows,2,i*2+2, facecolor=tuple(rgb_geometric[0,i,:])) # ylabels if i!=0: @@ -122,10 +122,10 @@ for i in range(nrows): # LHS: additive - ax1 = fig.add_subplot(nrows,ncols,i*2+1, axisbg=tuple(rgb_add[0,i,:])) + ax1 = fig.add_subplot(nrows,ncols,i*2+1, facecolor=tuple(rgb_add[0,i,:])) # middle: multiplicative - ax2 = fig.add_subplot(nrows,ncols,i*2+2, axisbg=tuple(rgb_geometric[0,i,:])) + ax2 = fig.add_subplot(nrows,ncols,i*2+2, facecolor=tuple(rgb_geometric[0,i,:])) # ylabels if i!=0: diff --git a/examples/pylab_examples/axes_demo.py b/examples/pylab_examples/axes_demo.py index 25184e192442..7e425c932ad2 100644 --- a/examples/pylab_examples/axes_demo.py +++ b/examples/pylab_examples/axes_demo.py @@ -16,14 +16,14 @@ plt.title('Gaussian colored noise') # this is an inset axes over the main axes -a = plt.axes([.65, .6, .2, .2], axisbg='y') +a = plt.axes([.65, .6, .2, .2], facecolor='y') n, bins, patches = plt.hist(s, 400, normed=1) plt.title('Probability') plt.xticks([]) plt.yticks([]) # this is another inset axes over the main axes -a = plt.axes([0.2, 0.6, .2, .2], axisbg='y') +a = plt.axes([0.2, 0.6, .2, .2], facecolor='y') plt.plot(t[:len(r)], r) plt.title('Impulse response') plt.xlim(0, 0.2) diff --git a/examples/pylab_examples/color_demo.py b/examples/pylab_examples/color_demo.py old mode 100644 new mode 100755 index 9598195ad0d4..1d471b0086a9 --- a/examples/pylab_examples/color_demo.py +++ b/examples/pylab_examples/color_demo.py @@ -16,8 +16,8 @@ import matplotlib.pyplot as plt import numpy as np -plt.subplot(111, axisbg='darkslategray') -#subplot(111, axisbg='#ababab') +plt.subplot(111, facecolor='darkslategray') +#subplot(111, facecolor='#ababab') t = np.arange(0.0, 2.0, 0.01) s = np.sin(2*np.pi*t) plt.plot(t, s, 'y') diff --git a/examples/pylab_examples/finance_work2.py b/examples/pylab_examples/finance_work2.py index 1ed78c5651c4..6fa0f3244e58 100644 --- a/examples/pylab_examples/finance_work2.py +++ b/examples/pylab_examples/finance_work2.py @@ -99,10 +99,10 @@ def moving_average_convergence(x, nslow=26, nfast=12): fig = plt.figure(facecolor='white') axescolor = '#f6f6f6' # the axes background color -ax1 = fig.add_axes(rect1, axisbg=axescolor) # left, bottom, width, height -ax2 = fig.add_axes(rect2, axisbg=axescolor, sharex=ax1) +ax1 = fig.add_axes(rect1, facecolor=axescolor) # left, bottom, width, height +ax2 = fig.add_axes(rect2, facecolor=axescolor, sharex=ax1) ax2t = ax2.twinx() -ax3 = fig.add_axes(rect3, axisbg=axescolor, sharex=ax1) +ax3 = fig.add_axes(rect3, facecolor=axescolor, sharex=ax1) # plot the relative strength indicator diff --git a/examples/pylab_examples/fonts_demo.py b/examples/pylab_examples/fonts_demo.py index d1f4fe6cb823..5fbd40e8644b 100644 --- a/examples/pylab_examples/fonts_demo.py +++ b/examples/pylab_examples/fonts_demo.py @@ -7,7 +7,7 @@ from matplotlib.font_manager import FontProperties import matplotlib.pyplot as plt -plt.subplot(111, axisbg='w') +plt.subplot(111, facecolor='w') font0 = FontProperties() alignment = {'horizontalalignment': 'center', 'verticalalignment': 'baseline'} diff --git a/examples/pylab_examples/fonts_demo_kw.py b/examples/pylab_examples/fonts_demo_kw.py index 51cd11b8d61e..0beefd74a55a 100644 --- a/examples/pylab_examples/fonts_demo_kw.py +++ b/examples/pylab_examples/fonts_demo_kw.py @@ -7,7 +7,7 @@ import matplotlib.pyplot as plt import numpy as np -plt.subplot(111, axisbg='w') +plt.subplot(111, facecolor='w') alignment = {'horizontalalignment': 'center', 'verticalalignment': 'baseline'} # Show family options diff --git a/examples/pylab_examples/image_origin.py b/examples/pylab_examples/image_origin.py index 654c7f410822..4effdd66bbee 100755 --- a/examples/pylab_examples/image_origin.py +++ b/examples/pylab_examples/image_origin.py @@ -13,12 +13,12 @@ interp = 'bilinear' #interp = 'nearest' lim = -2, 11, -2, 6 -plt.subplot(211, axisbg='g') +plt.subplot(211, facecolor='g') plt.title('blue should be up') plt.imshow(x, origin='upper', interpolation=interp, cmap='jet') #plt.axis(lim) -plt.subplot(212, axisbg='y') +plt.subplot(212, facecolor='y') plt.title('blue should be down') plt.imshow(x, origin='lower', interpolation=interp, cmap='jet') #plt.axis(lim) diff --git a/examples/pylab_examples/logo.py b/examples/pylab_examples/logo.py index 2125f19da472..2c65e55581c3 100755 --- a/examples/pylab_examples/logo.py +++ b/examples/pylab_examples/logo.py @@ -15,7 +15,7 @@ # 0.0005 is the sample interval t = 0.0005 * np.arange(len(x)) plt.figure(1, figsize=(7, 1), dpi=100) -ax = plt.subplot(111, axisbg='y') +ax = plt.subplot(111, facecolor='y') plt.plot(t, x) plt.text(0.5, 0.5, 'matplotlib', color='r', fontsize=40, fontname=['Courier', 'DejaVu Sans Mono'], diff --git a/examples/pylab_examples/mathtext_demo.py b/examples/pylab_examples/mathtext_demo.py index bc335429976b..ec3e3536055f 100755 --- a/examples/pylab_examples/mathtext_demo.py +++ b/examples/pylab_examples/mathtext_demo.py @@ -9,7 +9,7 @@ fig = figure() fig.subplots_adjust(bottom=0.2) -ax = fig.add_subplot(111, axisbg='y') +ax = fig.add_subplot(111, facecolor='y') ax.plot([1, 2, 3], 'r') x = np.arange(0.0, 3.0, 0.1) diff --git a/examples/pylab_examples/mathtext_examples.py b/examples/pylab_examples/mathtext_examples.py index ec6269e8d70c..bee528de214d 100755 --- a/examples/pylab_examples/mathtext_examples.py +++ b/examples/pylab_examples/mathtext_examples.py @@ -61,7 +61,7 @@ def doall(): # Creating figure and axis. plt.figure(figsize=(6, 7)) - plt.axes([0.01, 0.01, 0.98, 0.90], axisbg="white", frameon=True) + plt.axes([0.01, 0.01, 0.98, 0.90], facecolor="white", frameon=True) plt.gca().set_xlim(0., 1.) plt.gca().set_ylim(0., 1.) plt.gca().set_title("Matplotlib's math rendering engine", diff --git a/examples/pylab_examples/matplotlib_icon.py b/examples/pylab_examples/matplotlib_icon.py index d9a40550980f..50c70eedc2d5 100644 --- a/examples/pylab_examples/matplotlib_icon.py +++ b/examples/pylab_examples/matplotlib_icon.py @@ -7,7 +7,7 @@ matplotlib.rc('grid', ls='-', lw=2, color='k') fig = plt.figure(figsize=(1, 1), dpi=72) -plt.axes([0.025, 0.025, 0.95, 0.95], axisbg='#bfd1d4') +plt.axes([0.025, 0.025, 0.95, 0.95], facecolor='#bfd1d4') t = np.arange(0, 2, 0.05) s = np.sin(2*np.pi*t) diff --git a/examples/pylab_examples/polar_legend.py b/examples/pylab_examples/polar_legend.py old mode 100644 new mode 100755 index 5f945fc9ca0f..8bd86f0e5d12 --- a/examples/pylab_examples/polar_legend.py +++ b/examples/pylab_examples/polar_legend.py @@ -10,7 +10,7 @@ # 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', axisbg='#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/examples/pylab_examples/quadmesh_demo.py b/examples/pylab_examples/quadmesh_demo.py old mode 100644 new mode 100755 index 9ffea6bd5b89..e47fd4e6bc1c --- a/examples/pylab_examples/quadmesh_demo.py +++ b/examples/pylab_examples/quadmesh_demo.py @@ -27,12 +27,12 @@ fig = figure() ax = fig.add_subplot(121) -ax.set_axis_bgcolor("#bdb76b") +ax.set_facecolor("#bdb76b") ax.pcolormesh(Qx, Qz, Z, shading='gouraud') ax.set_title('Without masked values') ax = fig.add_subplot(122) -ax.set_axis_bgcolor("#bdb76b") +ax.set_facecolor("#bdb76b") # You can control the color of the masked region: #cmap = cm.jet #cmap.set_bad('r', 1.0) diff --git a/examples/widgets/cursor.py b/examples/widgets/cursor.py old mode 100644 new mode 100755 index 2dda520774ee..9a5d6350a560 --- a/examples/widgets/cursor.py +++ b/examples/widgets/cursor.py @@ -6,7 +6,7 @@ fig = plt.figure(figsize=(8, 6)) -ax = fig.add_subplot(111, axisbg='#FFFFCC') +ax = fig.add_subplot(111, facecolor='#FFFFCC') x, y = 4*(np.random.rand(2, 100) - .5) ax.plot(x, y, 'o') diff --git a/examples/widgets/slider_demo.py b/examples/widgets/slider_demo.py index ba18fa5220b7..70e6cb8d1ea7 100644 --- a/examples/widgets/slider_demo.py +++ b/examples/widgets/slider_demo.py @@ -12,8 +12,8 @@ plt.axis([0, 1, -10, 10]) axcolor = 'lightgoldenrodyellow' -axfreq = plt.axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor) -axamp = plt.axes([0.25, 0.15, 0.65, 0.03], axisbg=axcolor) +axfreq = plt.axes([0.25, 0.1, 0.65, 0.03], facecolor=axcolor) +axamp = plt.axes([0.25, 0.15, 0.65, 0.03], facecolor=axcolor) sfreq = Slider(axfreq, 'Freq', 0.1, 30.0, valinit=f0) samp = Slider(axamp, 'Amp', 0.1, 10.0, valinit=a0) @@ -36,7 +36,7 @@ def reset(event): samp.reset() button.on_clicked(reset) -rax = plt.axes([0.025, 0.5, 0.15, 0.15], axisbg=axcolor) +rax = plt.axes([0.025, 0.5, 0.15, 0.15], facecolor=axcolor) radio = RadioButtons(rax, ('red', 'blue', 'green'), active=0) diff --git a/examples/widgets/span_selector.py b/examples/widgets/span_selector.py old mode 100644 new mode 100755 index de4152fd7f7e..13eef05e035e --- a/examples/widgets/span_selector.py +++ b/examples/widgets/span_selector.py @@ -8,7 +8,7 @@ from matplotlib.widgets import SpanSelector fig = plt.figure(figsize=(8, 6)) -ax = fig.add_subplot(211, axisbg='#FFFFCC') +ax = fig.add_subplot(211, facecolor='#FFFFCC') x = np.arange(0.0, 5.0, 0.01) y = np.sin(2*np.pi*x) + 0.5*np.random.randn(len(x)) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 572e9a4a24f4..bc403a847702 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -436,8 +436,6 @@ def __init__(self, fig, rect, *aspect* [ 'auto' | 'equal' | aspect_ratio ] *autoscale_on* [ *True* | *False* ] whether or not to autoscale the *viewlim* - *axis_bgcolor* any matplotlib color, see - :func:`~matplotlib.pyplot.colors` *axisbelow* draw the grids and ticks below the other artists *cursor_props* a (*float*, *color*) tuple @@ -509,6 +507,9 @@ def __init__(self, fig, rect, if axisbg is None: axisbg = rcParams['axes.facecolor'] + else: + cbook.warn_deprecated( + '2.0', name='axisbg', alternative='facecolor') self._axisbg = axisbg self._frameon = frameon self._axisbelow = rcParams['axes.axisbelow'] @@ -1065,6 +1066,14 @@ def clear(self): """clear the axes""" self.cla() + def get_facecolor(self): + return self.patch.get_facecolor() + get_fc = get_facecolor + + def set_facecolor(self, color): + return self.patch.set_facecolor(color) + set_fc = set_facecolor + def set_prop_cycle(self, *args, **kwargs): """ Set the property cycle for any future plot commands on this Axes. @@ -2620,10 +2629,12 @@ def set_axis_on(self): self.axison = True self.stale = True + @cbook.deprecated('2.0', alternative='get_facecolor') def get_axis_bgcolor(self): """Return the axis background color""" return self._axisbg + @cbook.deprecated('2.0', alternative='set_facecolor') def set_axis_bgcolor(self, color): """ set the axes background color @@ -2631,7 +2642,9 @@ 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._axisbg = color self.patch.set_facecolor(color) self.stale = True diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index b640fed01317..b17fb7691a49 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -851,7 +851,7 @@ def add_axes(self, *args, **kwargs): rect = l,b,w,h fig.add_axes(rect) - fig.add_axes(rect, frameon=False, axisbg='g') + fig.add_axes(rect, frameon=False, facecolor='g') fig.add_axes(rect, polar=True) fig.add_axes(rect, projection='polar') fig.add_axes(ax) @@ -932,7 +932,7 @@ def add_subplot(self, *args, **kwargs): fig.add_subplot(1,1,1) # add subplot with red background - fig.add_subplot(212, axisbg='r') + fig.add_subplot(212, facecolor='r') # add a polar subplot fig.add_subplot(111, projection='polar') diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 88979ec9bb5f..1b3fa152e5fc 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -831,28 +831,28 @@ def axes(*args, **kwargs): - ``axes()`` by itself creates a default full ``subplot(111)`` window axis. - - ``axes(rect, axisbg='w')`` where *rect* = [left, bottom, width, - height] in normalized (0, 1) units. *axisbg* is the background + - ``axes(rect, facecolor='w')`` where *rect* = [left, bottom, width, + height] in normalized (0, 1) units. *facecolor* is the background color for the axis, default white. - ``axes(h)`` where *h* is an axes instance makes *h* the current axis. An :class:`~matplotlib.axes.Axes` instance is returned. - ======= ============== ============================================== - kwarg Accepts Description - ======= ============== ============================================== - axisbg color the axes background color - frameon [True|False] display the frame? - sharex otherax current axes shares xaxis attribute - with otherax - sharey otherax current axes shares yaxis attribute - with otherax - polar [True|False] use a polar axes? - aspect [str | num] ['equal', 'auto'] or a number. If a number - the ratio of x-unit/y-unit in screen-space. - Also see - :meth:`~matplotlib.axes.Axes.set_aspect`. - ======= ============== ============================================== + ========= ============== ============================================== + kwarg Accepts Description + ========= ============== ============================================== + facecolor color the axes background color + frameon [True|False] display the frame? + sharex otherax current axes shares xaxis attribute + with otherax + sharey otherax current axes shares yaxis attribute + with otherax + polar [True|False] use a polar axes? + aspect [str | num] ['equal', 'auto'] or a number. If a number + the ratio of x-unit/y-unit in screen-space. + Also see + :meth:`~matplotlib.axes.Axes.set_aspect`. + ========= ============== ============================================== Examples: @@ -968,7 +968,7 @@ def subplot(*args, **kwargs): # first, the plot (and its axes) previously created, will be removed plt.subplot(211) plt.plot(range(12)) - plt.subplot(212, axisbg='y') # creates 2nd subplot with yellow background + plt.subplot(212, facecolor='y') # creates 2nd subplot with yellow background If you do not want this behavior, use the :meth:`~matplotlib.figure.Figure.add_subplot` method or the @@ -976,7 +976,7 @@ def subplot(*args, **kwargs): Keyword arguments: - *axisbg*: + *facecolor*: The background color of the subplot, which can be any valid color specifier. See :mod:`matplotlib.colors` for more information. @@ -1919,7 +1919,7 @@ def colors(): The example below creates a subplot with a dark slate gray background:: - subplot(111, axisbg=(0.1843, 0.3098, 0.3098)) + subplot(111, facecolor=(0.1843, 0.3098, 0.3098)) Here is an example that creates a pale turquoise title:: diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index b6a4e79dc44f..d43460885f43 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -14,6 +14,8 @@ from numpy import ma from numpy import arange +import warnings + import matplotlib from matplotlib.testing.decorators import image_comparison, cleanup import matplotlib.pyplot as plt @@ -4088,6 +4090,17 @@ def test_violin_point_mass(): """Violin plot should handle point mass pdf gracefully.""" plt.violinplot(np.array([0, 0])) + +@cleanup +def test_axisbg_warning(): + fig = plt.figure() + with warnings.catch_warnings(record=True) as w: + ax = matplotlib.axes.Axes(fig, [0, 0, 1, 1], axisbg='r') + assert len(w) == 1 + assert (str(w[0].message).startswith( + ("The axisbg attribute was deprecated in version 2.0."))) + + if __name__ == '__main__': import nose import sys diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index ef5108c88457..fde7c7cc18c8 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -325,7 +325,7 @@ def test_image_composite_background(): arr = np.arange(12).reshape(4, 3) ax.imshow(arr, extent=[0, 2, 15, 0]) ax.imshow(arr, extent=[4, 6, 15, 0]) - ax.set_axis_bgcolor((1, 0, 0, 0.5)) + ax.set_facecolor((1, 0, 0, 0.5)) ax.set_xlim([0, 12]) @image_comparison(baseline_images=['image_composite_alpha'], remove_text=True) @@ -349,7 +349,7 @@ def test_image_composite_alpha(): ax.imshow(arr2, extent=[0, 5, 1, 2]) ax.imshow(arr2, extent=[0, 5, 2, 3], alpha=0.6) ax.imshow(arr2, extent=[0, 5, 3, 4], alpha=0.3) - ax.set_axis_bgcolor((0, 0.5, 0, 1)) + ax.set_facecolor((0, 0.5, 0, 1)) ax.set_xlim([0, 5]) ax.set_ylim([5, 0]) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index 94042a59e3bf..006f70169ae3 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -198,7 +198,7 @@ def __init__(self, ax, label, image=None, self.connect_event('button_release_event', self._release) self.connect_event('motion_notify_event', self._motion) ax.set_navigate(False) - ax.set_axis_bgcolor(color) + ax.set_facecolor(color) ax.set_xticks([]) ax.set_yticks([]) self.color = color @@ -237,7 +237,7 @@ def _motion(self, event): else: c = self.color if c != self._lastcolor: - self.ax.set_axis_bgcolor(c) + self.ax.set_facecolor(c) self._lastcolor = c if self.drawon: self.ax.figure.canvas.draw() @@ -523,7 +523,7 @@ def __init__(self, ax, labels, actives): ys = [0.5] cnt = 0 - axcolor = ax.get_axis_bgcolor() + axcolor = ax.get_facecolor() self.labels = [] self.lines = [] @@ -671,7 +671,7 @@ def __init__(self, ax, labels, active=0, activecolor='blue'): dy = 1. / (len(labels) + 1) ys = np.linspace(1 - dy, dy, len(labels)) cnt = 0 - axcolor = ax.get_axis_bgcolor() + axcolor = ax.get_facecolor() self.labels = [] self.circles = [] @@ -740,7 +740,7 @@ def set_active(self, index): if i == index: color = self.activecolor else: - color = self.ax.get_axis_bgcolor() + color = self.ax.get_facecolor() p.set_facecolor(color) if self.drawon: