Skip to content

Commit 5f1127c

Browse files
pelsonmdboom
authored andcommitted
Merge pull request #5501 from mdboom/axisbg
Use facecolor instead of axisbg/axis_bgcolor
1 parent d11e344 commit 5f1127c

22 files changed

+79
-56
lines changed

doc/api/api_changes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ sources of the changes you are experiencing.
1111
For new features that were added to matplotlib, please see
1212
:ref:`whats-new`.
1313

14+
Changes in 2.0.0
15+
================
16+
17+
Color of Axes
18+
-------------
19+
20+
The ``axisbg`` and ``axis_bgcolor`` properties on ``Axes`` have been
21+
deprecated in favor of ``facecolor``.
22+
1423
Changes in 1.5.0
1524
================
1625

examples/pylab_examples/axes_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
plt.title('Gaussian colored noise')
1717

1818
# this is an inset axes over the main axes
19-
a = plt.axes([.65, .6, .2, .2], axisbg='y')
19+
a = plt.axes([.65, .6, .2, .2], facecolor='y')
2020
n, bins, patches = plt.hist(s, 400, normed=1)
2121
plt.title('Probability')
2222
plt.xticks([])
2323
plt.yticks([])
2424

2525
# this is another inset axes over the main axes
26-
a = plt.axes([0.2, 0.6, .2, .2], axisbg='y')
26+
a = plt.axes([0.2, 0.6, .2, .2], facecolor='y')
2727
plt.plot(t[:len(r)], r)
2828
plt.title('Impulse response')
2929
plt.xlim(0, 0.2)

examples/pylab_examples/color_demo.py

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import matplotlib.pyplot as plt
1717
import numpy as np
1818

19-
plt.subplot(111, axisbg='darkslategray')
20-
#subplot(111, axisbg='#ababab')
19+
plt.subplot(111, facecolor='darkslategray')
20+
#subplot(111, facecolor='#ababab')
2121
t = np.arange(0.0, 2.0, 0.01)
2222
s = np.sin(2*np.pi*t)
2323
plt.plot(t, s, 'y')

examples/pylab_examples/finance_work2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ def moving_average_convergence(x, nslow=26, nfast=12):
9999
fig = plt.figure(facecolor='white')
100100
axescolor = '#f6f6f6' # the axes background color
101101

102-
ax1 = fig.add_axes(rect1, axisbg=axescolor) # left, bottom, width, height
103-
ax2 = fig.add_axes(rect2, axisbg=axescolor, sharex=ax1)
102+
ax1 = fig.add_axes(rect1, facecolor=axescolor) # left, bottom, width, height
103+
ax2 = fig.add_axes(rect2, facecolor=axescolor, sharex=ax1)
104104
ax2t = ax2.twinx()
105-
ax3 = fig.add_axes(rect3, axisbg=axescolor, sharex=ax1)
105+
ax3 = fig.add_axes(rect3, facecolor=axescolor, sharex=ax1)
106106

107107

108108
# plot the relative strength indicator

examples/pylab_examples/fonts_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from matplotlib.font_manager import FontProperties
88
import matplotlib.pyplot as plt
99

10-
plt.subplot(111, axisbg='w')
10+
plt.subplot(111, facecolor='w')
1111

1212
font0 = FontProperties()
1313
alignment = {'horizontalalignment': 'center', 'verticalalignment': 'baseline'}

examples/pylab_examples/fonts_demo_kw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import matplotlib.pyplot as plt
88
import numpy as np
99

10-
plt.subplot(111, axisbg='w')
10+
plt.subplot(111, facecolor='w')
1111
alignment = {'horizontalalignment': 'center', 'verticalalignment': 'baseline'}
1212

1313
# Show family options

examples/pylab_examples/image_origin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
interp = 'bilinear'
1414
#interp = 'nearest'
1515
lim = -2, 11, -2, 6
16-
plt.subplot(211, axisbg='g')
16+
plt.subplot(211, facecolor='g')
1717
plt.title('blue should be up')
1818
plt.imshow(x, origin='upper', interpolation=interp, cmap='jet')
1919
#plt.axis(lim)
2020

21-
plt.subplot(212, axisbg='y')
21+
plt.subplot(212, facecolor='y')
2222
plt.title('blue should be down')
2323
plt.imshow(x, origin='lower', interpolation=interp, cmap='jet')
2424
#plt.axis(lim)

examples/pylab_examples/logo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# 0.0005 is the sample interval
1616
t = 0.0005 * np.arange(len(x))
1717
plt.figure(1, figsize=(7, 1), dpi=100)
18-
ax = plt.subplot(111, axisbg='y')
18+
ax = plt.subplot(111, facecolor='y')
1919
plt.plot(t, x)
2020
plt.text(0.5, 0.5, 'matplotlib', color='r',
2121
fontsize=40, fontname=['Courier', 'DejaVu Sans Mono'],

examples/pylab_examples/mathtext_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
fig = figure()
1010
fig.subplots_adjust(bottom=0.2)
1111

12-
ax = fig.add_subplot(111, axisbg='y')
12+
ax = fig.add_subplot(111, facecolor='y')
1313
ax.plot([1, 2, 3], 'r')
1414
x = np.arange(0.0, 3.0, 0.1)
1515

examples/pylab_examples/mathtext_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def doall():
6161

6262
# Creating figure and axis.
6363
plt.figure(figsize=(6, 7))
64-
plt.axes([0.01, 0.01, 0.98, 0.90], axisbg="white", frameon=True)
64+
plt.axes([0.01, 0.01, 0.98, 0.90], facecolor="white", frameon=True)
6565
plt.gca().set_xlim(0., 1.)
6666
plt.gca().set_ylim(0., 1.)
6767
plt.gca().set_title("Matplotlib's math rendering engine",

examples/pylab_examples/matplotlib_icon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
matplotlib.rc('grid', ls='-', lw=2, color='k')
99
fig = plt.figure(figsize=(1, 1), dpi=72)
10-
plt.axes([0.025, 0.025, 0.95, 0.95], axisbg='#bfd1d4')
10+
plt.axes([0.025, 0.025, 0.95, 0.95], facecolor='#bfd1d4')
1111

1212
t = np.arange(0, 2, 0.05)
1313
s = np.sin(2*np.pi*t)

examples/pylab_examples/polar_legend.py

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
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', axisbg='#d5de9c')
13+
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], projection='polar', facecolor='#d5de9c')
1414

1515
r = np.arange(0, 3.0, 0.01)
1616
theta = 2*np.pi*r

examples/pylab_examples/quadmesh_demo.py

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727

2828
fig = figure()
2929
ax = fig.add_subplot(121)
30-
ax.set_axis_bgcolor("#bdb76b")
30+
ax.set_facecolor("#bdb76b")
3131
ax.pcolormesh(Qx, Qz, Z, shading='gouraud')
3232
ax.set_title('Without masked values')
3333

3434
ax = fig.add_subplot(122)
35-
ax.set_axis_bgcolor("#bdb76b")
35+
ax.set_facecolor("#bdb76b")
3636
# You can control the color of the masked region:
3737
#cmap = cm.jet
3838
#cmap.set_bad('r', 1.0)

examples/widgets/cursor.py

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
fig = plt.figure(figsize=(8, 6))
9-
ax = fig.add_subplot(111, axisbg='#FFFFCC')
9+
ax = fig.add_subplot(111, facecolor='#FFFFCC')
1010

1111
x, y = 4*(np.random.rand(2, 100) - .5)
1212
ax.plot(x, y, 'o')

examples/widgets/slider_demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
plt.axis([0, 1, -10, 10])
1313

1414
axcolor = 'lightgoldenrodyellow'
15-
axfreq = plt.axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor)
16-
axamp = plt.axes([0.25, 0.15, 0.65, 0.03], axisbg=axcolor)
15+
axfreq = plt.axes([0.25, 0.1, 0.65, 0.03], facecolor=axcolor)
16+
axamp = plt.axes([0.25, 0.15, 0.65, 0.03], facecolor=axcolor)
1717

1818
sfreq = Slider(axfreq, 'Freq', 0.1, 30.0, valinit=f0)
1919
samp = Slider(axamp, 'Amp', 0.1, 10.0, valinit=a0)
@@ -36,7 +36,7 @@ def reset(event):
3636
samp.reset()
3737
button.on_clicked(reset)
3838

39-
rax = plt.axes([0.025, 0.5, 0.15, 0.15], axisbg=axcolor)
39+
rax = plt.axes([0.025, 0.5, 0.15, 0.15], facecolor=axcolor)
4040
radio = RadioButtons(rax, ('red', 'blue', 'green'), active=0)
4141

4242

examples/widgets/span_selector.py

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from matplotlib.widgets import SpanSelector
99

1010
fig = plt.figure(figsize=(8, 6))
11-
ax = fig.add_subplot(211, axisbg='#FFFFCC')
11+
ax = fig.add_subplot(211, facecolor='#FFFFCC')
1212

1313
x = np.arange(0.0, 5.0, 0.01)
1414
y = np.sin(2*np.pi*x) + 0.5*np.random.randn(len(x))

lib/matplotlib/axes/_base.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,6 @@ def __init__(self, fig, rect,
438438
*aspect* [ 'auto' | 'equal' | aspect_ratio ]
439439
*autoscale_on* [ *True* | *False* ] whether or not to
440440
autoscale the *viewlim*
441-
*axis_bgcolor* any matplotlib color, see
442-
:func:`~matplotlib.pyplot.colors`
443441
*axisbelow* draw the grids and ticks below the other
444442
artists
445443
*cursor_props* a (*float*, *color*) tuple
@@ -511,6 +509,9 @@ def __init__(self, fig, rect,
511509

512510
if axisbg is None:
513511
axisbg = rcParams['axes.facecolor']
512+
else:
513+
cbook.warn_deprecated(
514+
'2.0', name='axisbg', alternative='facecolor')
514515
self._axisbg = axisbg
515516
self._frameon = frameon
516517
self._axisbelow = rcParams['axes.axisbelow']
@@ -1071,6 +1072,14 @@ def clear(self):
10711072
"""clear the axes"""
10721073
self.cla()
10731074

1075+
def get_facecolor(self):
1076+
return self.patch.get_facecolor()
1077+
get_fc = get_facecolor
1078+
1079+
def set_facecolor(self, color):
1080+
return self.patch.set_facecolor(color)
1081+
set_fc = set_facecolor
1082+
10741083
def set_prop_cycle(self, *args, **kwargs):
10751084
"""
10761085
Set the property cycle for any future plot commands on this Axes.
@@ -2677,18 +2686,22 @@ def set_axis_on(self):
26772686
self.axison = True
26782687
self.stale = True
26792688

2689+
@cbook.deprecated('2.0', alternative='get_facecolor')
26802690
def get_axis_bgcolor(self):
26812691
"""Return the axis background color"""
26822692
return self._axisbg
26832693

2694+
@cbook.deprecated('2.0', alternative='set_facecolor')
26842695
def set_axis_bgcolor(self, color):
26852696
"""
26862697
set the axes background color
26872698
26882699
ACCEPTS: any matplotlib color - see
26892700
:func:`~matplotlib.pyplot.colors`
26902701
"""
2691-
2702+
warnings.warn(
2703+
"set_axis_bgcolor is deprecated. Use set_facecolor instead.",
2704+
cbook.mplDeprecation)
26922705
self._axisbg = color
26932706
self.patch.set_facecolor(color)
26942707
self.stale = True

lib/matplotlib/figure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ def add_axes(self, *args, **kwargs):
851851
852852
rect = l,b,w,h
853853
fig.add_axes(rect)
854-
fig.add_axes(rect, frameon=False, axisbg='g')
854+
fig.add_axes(rect, frameon=False, facecolor='g')
855855
fig.add_axes(rect, polar=True)
856856
fig.add_axes(rect, projection='polar')
857857
fig.add_axes(ax)
@@ -932,7 +932,7 @@ def add_subplot(self, *args, **kwargs):
932932
fig.add_subplot(1,1,1)
933933
934934
# add subplot with red background
935-
fig.add_subplot(212, axisbg='r')
935+
fig.add_subplot(212, facecolor='r')
936936
937937
# add a polar subplot
938938
fig.add_subplot(111, projection='polar')

lib/matplotlib/pyplot.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -831,28 +831,28 @@ def axes(*args, **kwargs):
831831
832832
- ``axes()`` by itself creates a default full ``subplot(111)`` window axis.
833833
834-
- ``axes(rect, axisbg='w')`` where *rect* = [left, bottom, width,
835-
height] in normalized (0, 1) units. *axisbg* is the background
834+
- ``axes(rect, facecolor='w')`` where *rect* = [left, bottom, width,
835+
height] in normalized (0, 1) units. *facecolor* is the background
836836
color for the axis, default white.
837837
838838
- ``axes(h)`` where *h* is an axes instance makes *h* the current
839839
axis. An :class:`~matplotlib.axes.Axes` instance is returned.
840840
841-
======= ============== ==============================================
842-
kwarg Accepts Description
843-
======= ============== ==============================================
844-
axisbg color the axes background color
845-
frameon [True|False] display the frame?
846-
sharex otherax current axes shares xaxis attribute
847-
with otherax
848-
sharey otherax current axes shares yaxis attribute
849-
with otherax
850-
polar [True|False] use a polar axes?
851-
aspect [str | num] ['equal', 'auto'] or a number. If a number
852-
the ratio of x-unit/y-unit in screen-space.
853-
Also see
854-
:meth:`~matplotlib.axes.Axes.set_aspect`.
855-
======= ============== ==============================================
841+
========= ============== ==============================================
842+
kwarg Accepts Description
843+
========= ============== ==============================================
844+
facecolor color the axes background color
845+
frameon [True|False] display the frame?
846+
sharex otherax current axes shares xaxis attribute
847+
with otherax
848+
sharey otherax current axes shares yaxis attribute
849+
with otherax
850+
polar [True|False] use a polar axes?
851+
aspect [str | num] ['equal', 'auto'] or a number. If a number
852+
the ratio of x-unit/y-unit in screen-space.
853+
Also see
854+
:meth:`~matplotlib.axes.Axes.set_aspect`.
855+
========= ============== ==============================================
856856
857857
Examples:
858858
@@ -968,15 +968,15 @@ def subplot(*args, **kwargs):
968968
# first, the plot (and its axes) previously created, will be removed
969969
plt.subplot(211)
970970
plt.plot(range(12))
971-
plt.subplot(212, axisbg='y') # creates 2nd subplot with yellow background
971+
plt.subplot(212, facecolor='y') # creates 2nd subplot with yellow background
972972
973973
If you do not want this behavior, use the
974974
:meth:`~matplotlib.figure.Figure.add_subplot` method or the
975975
:func:`~matplotlib.pyplot.axes` function instead.
976976
977977
Keyword arguments:
978978
979-
*axisbg*:
979+
*facecolor*:
980980
The background color of the subplot, which can be any valid
981981
color specifier. See :mod:`matplotlib.colors` for more
982982
information.
@@ -1919,7 +1919,7 @@ def colors():
19191919
The example below creates a subplot with a dark
19201920
slate gray background::
19211921
1922-
subplot(111, axisbg=(0.1843, 0.3098, 0.3098))
1922+
subplot(111, facecolor=(0.1843, 0.3098, 0.3098))
19231923
19241924
Here is an example that creates a pale turquoise title::
19251925

lib/matplotlib/tests/test_axes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from numpy import ma
1515
from numpy import arange
1616

17+
import warnings
18+
1719
import matplotlib
1820
from matplotlib.testing.decorators import image_comparison, cleanup
1921
import matplotlib.pyplot as plt
@@ -4110,7 +4112,6 @@ def test_violin_point_mass():
41104112
plt.violinplot(np.array([0, 0]))
41114113

41124114

4113-
41144115
@cleanup
41154116
def test_axisbg_warning():
41164117
fig = plt.figure()

lib/matplotlib/tests/test_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def test_image_composite_background():
325325
arr = np.arange(12).reshape(4, 3)
326326
ax.imshow(arr, extent=[0, 2, 15, 0])
327327
ax.imshow(arr, extent=[4, 6, 15, 0])
328-
ax.set_axis_bgcolor((1, 0, 0, 0.5))
328+
ax.set_facecolor((1, 0, 0, 0.5))
329329
ax.set_xlim([0, 12])
330330

331331
@image_comparison(baseline_images=['image_composite_alpha'], remove_text=True)
@@ -349,7 +349,7 @@ def test_image_composite_alpha():
349349
ax.imshow(arr2, extent=[0, 5, 1, 2])
350350
ax.imshow(arr2, extent=[0, 5, 2, 3], alpha=0.6)
351351
ax.imshow(arr2, extent=[0, 5, 3, 4], alpha=0.3)
352-
ax.set_axis_bgcolor((0, 0.5, 0, 1))
352+
ax.set_facecolor((0, 0.5, 0, 1))
353353
ax.set_xlim([0, 5])
354354
ax.set_ylim([5, 0])
355355

0 commit comments

Comments
 (0)