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

Skip to content

Commit 8da435d

Browse files
committed
Merge pull request #5501 from mdboom/axisbg
Use facecolor instead of axisbg/axis_bgcolor
2 parents f90367a + 7840328 commit 8da435d

23 files changed

+94
-59
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

doc/users/plotting/colormaps/Lfunction.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
for i in range(red.shape[1]):
5050

5151
# LHS: additive
52-
ax1 = fig.add_subplot(nrows,2,i*2+1, axisbg=tuple(rgb_add[0,i,:]))
52+
ax1 = fig.add_subplot(nrows,2,i*2+1, facecolor=tuple(rgb_add[0,i,:]))
5353

5454
# RHS: multiplicative
55-
ax2 = fig.add_subplot(nrows,2,i*2+2, axisbg=tuple(rgb_geometric[0,i,:]))
55+
ax2 = fig.add_subplot(nrows,2,i*2+2, facecolor=tuple(rgb_geometric[0,i,:]))
5656

5757
# ylabels
5858
if i!=0:
@@ -122,10 +122,10 @@
122122
for i in range(nrows):
123123

124124
# LHS: additive
125-
ax1 = fig.add_subplot(nrows,ncols,i*2+1, axisbg=tuple(rgb_add[0,i,:]))
125+
ax1 = fig.add_subplot(nrows,ncols,i*2+1, facecolor=tuple(rgb_add[0,i,:]))
126126

127127
# middle: multiplicative
128-
ax2 = fig.add_subplot(nrows,ncols,i*2+2, axisbg=tuple(rgb_geometric[0,i,:]))
128+
ax2 = fig.add_subplot(nrows,ncols,i*2+2, facecolor=tuple(rgb_geometric[0,i,:]))
129129

130130
# ylabels
131131
if i!=0:

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
@@ -436,8 +436,6 @@ def __init__(self, fig, rect,
436436
*aspect* [ 'auto' | 'equal' | aspect_ratio ]
437437
*autoscale_on* [ *True* | *False* ] whether or not to
438438
autoscale the *viewlim*
439-
*axis_bgcolor* any matplotlib color, see
440-
:func:`~matplotlib.pyplot.colors`
441439
*axisbelow* draw the grids and ticks below the other
442440
artists
443441
*cursor_props* a (*float*, *color*) tuple
@@ -509,6 +507,9 @@ def __init__(self, fig, rect,
509507

510508
if axisbg is None:
511509
axisbg = rcParams['axes.facecolor']
510+
else:
511+
cbook.warn_deprecated(
512+
'2.0', name='axisbg', alternative='facecolor')
512513
self._axisbg = axisbg
513514
self._frameon = frameon
514515
self._axisbelow = rcParams['axes.axisbelow']
@@ -1069,6 +1070,14 @@ def clear(self):
10691070
"""clear the axes"""
10701071
self.cla()
10711072

1073+
def get_facecolor(self):
1074+
return self.patch.get_facecolor()
1075+
get_fc = get_facecolor
1076+
1077+
def set_facecolor(self, color):
1078+
return self.patch.set_facecolor(color)
1079+
set_fc = set_facecolor
1080+
10721081
def set_prop_cycle(self, *args, **kwargs):
10731082
"""
10741083
Set the property cycle for any future plot commands on this Axes.
@@ -2624,18 +2633,22 @@ def set_axis_on(self):
26242633
self.axison = True
26252634
self.stale = True
26262635

2636+
@cbook.deprecated('2.0', alternative='get_facecolor')
26272637
def get_axis_bgcolor(self):
26282638
"""Return the axis background color"""
26292639
return self._axisbg
26302640

2641+
@cbook.deprecated('2.0', alternative='set_facecolor')
26312642
def set_axis_bgcolor(self, color):
26322643
"""
26332644
set the axes background color
26342645
26352646
ACCEPTS: any matplotlib color - see
26362647
:func:`~matplotlib.pyplot.colors`
26372648
"""
2638-
2649+
warnings.warn(
2650+
"set_axis_bgcolor is deprecated. Use set_facecolor instead.",
2651+
cbook.mplDeprecation)
26392652
self._axisbg = color
26402653
self.patch.set_facecolor(color)
26412654
self.stale = True

lib/matplotlib/figure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ def add_axes(self, *args, **kwargs):
852852
853853
rect = l,b,w,h
854854
fig.add_axes(rect)
855-
fig.add_axes(rect, frameon=False, axisbg='g')
855+
fig.add_axes(rect, frameon=False, facecolor='g')
856856
fig.add_axes(rect, polar=True)
857857
fig.add_axes(rect, projection='polar')
858858
fig.add_axes(ax)
@@ -933,7 +933,7 @@ def add_subplot(self, *args, **kwargs):
933933
fig.add_subplot(1,1,1)
934934
935935
# add subplot with red background
936-
fig.add_subplot(212, axisbg='r')
936+
fig.add_subplot(212, facecolor='r')
937937
938938
# add a polar subplot
939939
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.
@@ -1824,7 +1824,7 @@ def colors():
18241824
The example below creates a subplot with a dark
18251825
slate gray background::
18261826
1827-
subplot(111, axisbg=(0.1843, 0.3098, 0.3098))
1827+
subplot(111, facecolor=(0.1843, 0.3098, 0.3098))
18281828
18291829
Here is an example that creates a pale turquoise title::
18301830

lib/matplotlib/tests/test_axes.py

Lines changed: 13 additions & 0 deletions
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
@@ -4105,6 +4107,17 @@ def test_violin_point_mass():
41054107
"""Violin plot should handle point mass pdf gracefully."""
41064108
plt.violinplot(np.array([0, 0]))
41074109

4110+
4111+
@cleanup
4112+
def test_axisbg_warning():
4113+
fig = plt.figure()
4114+
with warnings.catch_warnings(record=True) as w:
4115+
ax = matplotlib.axes.Axes(fig, [0, 0, 1, 1], axisbg='r')
4116+
assert len(w) == 1
4117+
assert (str(w[0].message).startswith(
4118+
("The axisbg attribute was deprecated in version 2.0.")))
4119+
4120+
41084121
if __name__ == '__main__':
41094122
import nose
41104123
import sys

0 commit comments

Comments
 (0)