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

Skip to content

Commit 57c845b

Browse files
committed
Merge remote-tracking branch 'matplotlib/v2.x'
Conflicts: lib/matplotlib/pyplot.py - kept imports from 2.x. There was some style clean up on the master branch, but added imports on 2.x - re-ran boilerplate.py with this code pre-commit
2 parents c260365 + 8251436 commit 57c845b

33 files changed

+597
-360
lines changed

boilerplate.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,19 @@
5050
@_autogen_docstring(Axes.%(func)s)
5151
def %(func)s(%(argspec)s):
5252
%(ax)s = gca()
53-
# allow callers to override the hold state by passing hold=True|False
54-
%(washold)s = %(ax)s.ishold()
53+
# Deprecated: allow callers to override the hold state
54+
# by passing hold=True|False
55+
%(washold)s = %(ax)s._hold
5556
%(sethold)s
5657
if hold is not None:
57-
%(ax)s.hold(hold)
58+
%(ax)s._hold = hold
59+
from matplotlib.cbook import mplDeprecation
60+
warnings.warn("The 'hold' keyword argument is deprecated since 2.0.",
61+
mplDeprecation)
5862
try:
5963
%(ret)s = %(ax)s.%(func)s(%(call)s)
6064
finally:
61-
%(ax)s.hold(%(washold)s)
65+
%(ax)s._hold = %(washold)s
6266
%(mappable)s
6367
return %(ret)s
6468
"""

doc/api/api_changes.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Color of Axes
2222
The ``axisbg`` and ``axis_bgcolor`` properties on ``Axes`` have been
2323
deprecated in favor of ``facecolor``.
2424

25-
2625
GTK and GDK backends deprecated
2726
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2827
The GDK and GTK backends have been deprecated. These obsolete backends
@@ -41,6 +40,16 @@ CocoaAgg backend removed
4140
~~~~~~~~~~~~~~~~~~~~~~~~
4241
The deprecated and not fully functional CocoaAgg backend has been removed.
4342

43+
'hold' functionality deprecated
44+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45+
The 'hold' keyword argument and all functions and methods related
46+
to it are deprecated, along with the 'axes.hold' `rcParams` entry.
47+
The behavior will remain consistent with the default ``hold=True``
48+
state that has long been in place. Instead of using a function
49+
or keyword argument (``hold=False``) to change that behavior,
50+
explicitly clear the axes or figure as needed prior to subsequent
51+
plotting commands.
52+
4453

4554
`Artist.update` has return value
4655
--------------------------------

doc/sphinxext/gen_gallery.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- coding: UTF-8 -*-
1+
# -*- coding: utf-8 -*-
22
import codecs
33
import os
44
import re
@@ -14,7 +14,7 @@
1414
multiimage = re.compile('(.*?)(_\d\d){1,2}')
1515

1616
# generate a thumbnail gallery of examples
17-
gallery_template = """\
17+
gallery_template = u"""\
1818
{{% extends "layout.html" %}}
1919
{{% set title = "Thumbnail gallery" %}}
2020
@@ -35,7 +35,7 @@
3535
{{% endblock %}}
3636
"""
3737

38-
header_template = """\
38+
header_template = u"""\
3939
<div class="section" id="{section}">
4040
<h4>
4141
{title}<a class="headerlink" href="#{section}" title="Permalink to this headline">¶</a>
@@ -48,7 +48,7 @@
4848
</figure>
4949
"""
5050

51-
toc_template = """\
51+
toc_template = u"""\
5252
<li><a class="reference internal" href="#{section}">{title}</a></li>"""
5353

5454

@@ -133,10 +133,10 @@ def gen_gallery(app, doctree):
133133
warnings.warn("No thumbnails were found in %s" % subdir)
134134

135135
# Close out the <div> opened up at the top of this loop
136-
rows.append("</div>")
136+
rows.append(u"</div>")
137137

138-
content = gallery_template.format(toc='\n'.join(toc_rows),
139-
gallery='\n'.join(rows))
138+
content = gallery_template.format(toc=u'\n'.join(toc_rows),
139+
gallery=u'\n'.join(rows))
140140

141141
# Only write out the file if the contents have actually changed.
142142
# Otherwise, this triggers a full rebuild of the docs

examples/pylab_examples/contour_image.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())
3030
cmap = cm.PRGn
3131

32-
plt.figure()
32+
fig = plt.figure()
33+
fig.subplots_adjust(hspace=0.3)
3334

3435

3536
plt.subplot(2, 2, 1)
@@ -46,42 +47,38 @@
4647
# contour separately; don't try to change the edgecolor or edgewidth
4748
# of the polygons in the collections returned by contourf.
4849
# Use levels output from previous call to guarantee they are the same.
49-
cset2 = plt.contour(X, Y, Z, cset1.levels,
50-
colors='k',
51-
hold='on')
50+
51+
cset2 = plt.contour(X, Y, Z, cset1.levels, colors='k')
52+
5253
# We don't really need dashed contour lines to indicate negative
5354
# regions, so let's turn them off.
55+
5456
for c in cset2.collections:
5557
c.set_linestyle('solid')
5658

5759
# It is easier here to make a separate call to contour than
5860
# to set up an array of colors and linewidths.
5961
# We are making a thick green line as a zero contour.
6062
# Specify the zero level as a tuple with only 0 in it.
61-
cset3 = plt.contour(X, Y, Z, (0,),
62-
colors='g',
63-
linewidths=2,
64-
hold='on')
63+
64+
cset3 = plt.contour(X, Y, Z, (0,), colors='g', linewidths=2)
6565
plt.title('Filled contours')
6666
plt.colorbar(cset1)
67-
#hot()
6867

6968

7069
plt.subplot(2, 2, 2)
7170

7271
plt.imshow(Z, extent=extent, cmap=cmap, norm=norm)
7372
v = plt.axis()
74-
plt.contour(Z, levels, hold='on', colors='k',
75-
origin='upper', extent=extent)
73+
plt.contour(Z, levels, colors='k', origin='upper', extent=extent)
7674
plt.axis(v)
7775
plt.title("Image, origin 'upper'")
7876

7977
plt.subplot(2, 2, 3)
8078

8179
plt.imshow(Z, origin='lower', extent=extent, cmap=cmap, norm=norm)
8280
v = plt.axis()
83-
plt.contour(Z, levels, hold='on', colors='k',
84-
origin='lower', extent=extent)
81+
plt.contour(Z, levels, colors='k', origin='lower', extent=extent)
8582
plt.axis(v)
8683
plt.title("Image, origin 'lower'")
8784

@@ -95,12 +92,11 @@
9592
# domain that is contoured does not extend beyond these pixel centers.
9693
im = plt.imshow(Z, interpolation='nearest', extent=extent, cmap=cmap, norm=norm)
9794
v = plt.axis()
98-
plt.contour(Z, levels, hold='on', colors='k',
99-
origin='image', extent=extent)
95+
plt.contour(Z, levels, colors='k', origin='image', extent=extent)
10096
plt.axis(v)
10197
ylim = plt.get(plt.gca(), 'ylim')
10298
plt.setp(plt.gca(), ylim=ylim[::-1])
103-
plt.title("Image, origin from rc, reversed y-axis")
99+
plt.title("Origin from rc, reversed y-axis")
104100
plt.colorbar(im)
105101

106102
plt.show()

examples/pylab_examples/contourf_demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
interior = np.sqrt((X**2) + (Y**2)) < 0.5
2828
Z[interior] = np.ma.masked
2929

30-
3130
# We are using automatic selection of contour levels;
3231
# this is usually not such a good idea, because they don't
3332
# occur on nice boundaries, but we do it here for purposes
@@ -45,8 +44,7 @@
4544

4645
CS2 = plt.contour(CS, levels=CS.levels[::2],
4746
colors='r',
48-
origin=origin,
49-
hold='on')
47+
origin=origin)
5048

5149
plt.title('Nonsense (3 masked regions)')
5250
plt.xlabel('word length anomaly')
@@ -97,6 +95,8 @@
9795
# cmap.set_bad("red")
9896

9997
fig, axs = plt.subplots(2, 2)
98+
fig.subplots_adjust(hspace=0.3)
99+
100100
for ax, extend in zip(axs.ravel(), extends):
101101
cs = ax.contourf(X, Y, Z, levels, cmap=cmap, extend=extend, origin=origin)
102102
fig.colorbar(cs, ax=ax, shrink=0.9)

examples/pylab_examples/layer_images.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def func3(x, y):
3232
Z1.shape = (8, 8) # chessboard
3333
im1 = plt.imshow(Z1, cmap=plt.cm.gray, interpolation='nearest',
3434
extent=extent)
35-
plt.hold(True)
3635

3736
Z2 = func3(X, Y)
3837

examples/pylab_examples/scatter_masked.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
r = np.sqrt(x*x + y*y)
1515
area1 = np.ma.masked_where(r < r0, area)
1616
area2 = np.ma.masked_where(r >= r0, area)
17-
plt.scatter(x, y, s=area1, marker='^', c=c, hold='on')
17+
plt.scatter(x, y, s=area1, marker='^', c=c)
1818
plt.scatter(x, y, s=area2, marker='o', c=c)
1919
# Show the boundary between the regions:
2020
theta = np.arange(0, np.pi/2, 0.01)

examples/pylab_examples/toggle_images.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" toggle between two images by pressing "t"
22
33
The basic idea is to load two images (they can be different shapes) and plot
4-
them to the same axes with hold "on". Then, toggle the visible property of
4+
them to the same axes. Then, toggle the visible property of
55
them using keypress event handling
66
77
If you want two images with different shapes to be plotted with the same
@@ -31,7 +31,7 @@
3131
# them to be resampled into the same axes space
3232
extent = (0, 1, 0, 1)
3333
im1 = plt.imshow(x1, extent=extent)
34-
im2 = plt.imshow(x2, extent=extent, hold=True)
34+
im2 = plt.imshow(x2, extent=extent)
3535
im2.set_visible(False)
3636

3737

examples/user_interfaces/embedding_in_qt4.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,9 @@ class MyMplCanvas(FigureCanvas):
3333
def __init__(self, parent=None, width=5, height=4, dpi=100):
3434
fig = Figure(figsize=(width, height), dpi=dpi)
3535
self.axes = fig.add_subplot(111)
36-
# We want the axes cleared every time plot() is called
37-
self.axes.hold(False)
3836

3937
self.compute_initial_figure()
4038

41-
#
4239
FigureCanvas.__init__(self, fig)
4340
self.setParent(parent)
4441

@@ -75,7 +72,7 @@ def compute_initial_figure(self):
7572
def update_figure(self):
7673
# Build a list of 4 random integers between 0 and 10 (both inclusive)
7774
l = [random.randint(0, 10) for i in range(4)]
78-
75+
self.axes.cla()
7976
self.axes.plot([0, 1, 2, 3], l, 'r')
8077
self.draw()
8178

examples/user_interfaces/embedding_in_qt5.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ class MyMplCanvas(FigureCanvas):
3232
def __init__(self, parent=None, width=5, height=4, dpi=100):
3333
fig = Figure(figsize=(width, height), dpi=dpi)
3434
self.axes = fig.add_subplot(111)
35-
# We want the axes cleared every time plot() is called
36-
self.axes.hold(False)
3735

3836
self.compute_initial_figure()
3937

40-
#
4138
FigureCanvas.__init__(self, fig)
4239
self.setParent(parent)
4340

@@ -74,7 +71,7 @@ def compute_initial_figure(self):
7471
def update_figure(self):
7572
# Build a list of 4 random integers between 0 and 10 (both inclusive)
7673
l = [random.randint(0, 10) for i in range(4)]
77-
74+
self.axes.cla()
7875
self.axes.plot([0, 1, 2, 3], l, 'r')
7976
self.draw()
8077

extern/agg24-svn/include/agg_span_gouraud_rgba.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ namespace agg
198198
vg = g.y();
199199
vb = b.y();
200200
va = a.y();
201-
if(vr < 0) vr = 0; if(vr > lim) vr = lim;
202-
if(vg < 0) vg = 0; if(vg > lim) vg = lim;
203-
if(vb < 0) vb = 0; if(vb > lim) vb = lim;
204-
if(va < 0) va = 0; if(va > lim) va = lim;
201+
if(vr < 0) { vr = 0; }; if(vr > lim) { vr = lim; };
202+
if(vg < 0) { vg = 0; }; if(vg > lim) { vg = lim; };
203+
if(vb < 0) { vb = 0; }; if(vb > lim) { vb = lim; };
204+
if(va < 0) { va = 0; }; if(va > lim) { va = lim; };
205205
span->r = (value_type)vr;
206206
span->g = (value_type)vg;
207207
span->b = (value_type)vb;
@@ -245,10 +245,10 @@ namespace agg
245245
vg = g.y();
246246
vb = b.y();
247247
va = a.y();
248-
if(vr < 0) vr = 0; if(vr > lim) vr = lim;
249-
if(vg < 0) vg = 0; if(vg > lim) vg = lim;
250-
if(vb < 0) vb = 0; if(vb > lim) vb = lim;
251-
if(va < 0) va = 0; if(va > lim) va = lim;
248+
if(vr < 0) { vr = 0; }; if(vr > lim) { vr = lim; };
249+
if(vg < 0) { vg = 0; }; if(vg > lim) { vg = lim; };
250+
if(vb < 0) { vb = 0; }; if(vb > lim) { vb = lim; };
251+
if(va < 0) { va = 0; }; if(va > lim) { va = lim; };
252252
span->r = (value_type)vr;
253253
span->g = (value_type)vg;
254254
span->b = (value_type)vb;

lib/matplotlib/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,13 @@ def matplotlib_fname():
861861
}
862862

863863
_obsolete_set = set(['tk.pythoninspect', 'legend.isaxes'])
864+
865+
# The following may use a value of None to suppress the warning.
866+
_deprecated_set = set(['axes.hold']) # do NOT include in _all_deprecated
867+
864868
_all_deprecated = set(chain(_deprecated_ignore_map,
865-
_deprecated_map, _obsolete_set))
869+
_deprecated_map,
870+
_obsolete_set))
866871

867872

868873
class RcParams(dict):
@@ -878,6 +883,8 @@ class RcParams(dict):
878883
six.iteritems(defaultParams)
879884
if key not in _all_deprecated)
880885
msg_depr = "%s is deprecated and replaced with %s; please use the latter."
886+
msg_depr_set = ("%s is deprecated. Please remove it from your "
887+
"matplotlibrc and/or style files.")
881888
msg_depr_ignore = "%s is deprecated and ignored. Use %s"
882889
msg_obsolete = ("%s is obsolete. Please remove it from your matplotlibrc "
883890
"and/or style files.")
@@ -894,6 +901,8 @@ def __setitem__(self, key, val):
894901
warnings.warn(self.msg_depr % (key, alt_key))
895902
key = alt_key
896903
val = alt_val(val)
904+
elif key in _deprecated_set and val is not None:
905+
warnings.warn(self.msg_depr_set % key)
897906
elif key in _deprecated_ignore_map:
898907
alt = _deprecated_ignore_map[key]
899908
warnings.warn(self.msg_depr_ignore % (key, alt))

0 commit comments

Comments
 (0)