Skip to content

Commit 33b4cce

Browse files
committed
Merge branch 'use-subplots' into v1.3.x
2 parents 7634812 + e4dbbc6 commit 33b4cce

File tree

121 files changed

+253
-399
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+253
-399
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@
9090

9191
2012-11-09 Make plt.subplot() without arguments act as subplot(111) - PI
9292

93+
2012-11-08 Replaced plt.figure and plt.subplot calls by the newer, more
94+
convenient single call to plt.subplots() in the documentation
95+
examples - PI
96+
9397
2012-10-05 Add support for saving animations as animated GIFs. - JVDP
9498

9599
2012-08-11 Fix path-closing bug in patches.Polygon, so that regardless

doc/users/whats_new.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ Andrew Dawson added a new keyword argument *extendrect* to
138138
:meth:`~matplotlib.pyplot.colorbar` to optionally make colorbar
139139
extensions rectangular instead of triangular.
140140

141+
Examples now use subplots()
142+
---------------------------
143+
For the sake of brevity and clarity, most of the :ref:`examples
144+
<examples-index>` now use the newer :func:`~matplotlib.pyplot.subplots`, which
145+
creates a figure and one (or multiple) axes object(s) in one call. The old way
146+
involved a call to :func:`~matplotlib.pyplot.figure`, followed by one (or
147+
multiple) :func:`~matplotlib.pyplot.subplot` calls.
148+
141149
Calling subplot() without arguments
142150
-----------------------------------
143151
A call to :func:`~matplotlib.pyplot.subplot` without any arguments now

examples/animation/animate_decay.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ def data_gen():
1111
yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)
1212
data_gen.t = 0
1313

14-
fig = plt.figure()
15-
ax = fig.add_subplot(111)
14+
fig, ax = plt.subplots()
1615
line, = ax.plot([], [], lw=2)
1716
ax.set_ylim(-1.1, 1.1)
1817
ax.set_xlim(0, 5)

examples/animation/histogram.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
import matplotlib.path as path
1010
import matplotlib.animation as animation
1111

12-
fig = plt.figure()
13-
ax = fig.add_subplot(111)
12+
fig, ax = plt.subplots()
1413

1514
# histogram our data with numpy
1615
data = np.random.randn(1000)

examples/animation/old_animation/animate_decay_tk_blit.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ def data_gen():
1010
return np.sin(2*np.pi*t) * np.exp(-t/10.)
1111
data_gen.t = 0
1212

13-
fig = plt.figure()
14-
ax = fig.add_subplot(111)
13+
fig, ax = plt.subplots()
1514
line, = ax.plot([], [], animated=True, lw=2)
1615
ax.set_ylim(-1.1, 1.1)
1716
ax.set_xlim(0, 5)

examples/animation/old_animation/animation_blit_gtk.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
import matplotlib.pyplot as plt
1717

1818

19-
fig = plt.figure()
20-
ax = fig.add_subplot(111)
19+
fig, ax = plt.subplots()
2120
canvas = fig.canvas
2221

2322
fig.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs

examples/animation/old_animation/animation_blit_gtk2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,8 @@ def update_line(self, *args):
148148

149149

150150
plt.rcParams["text.usetex"] = False
151-
fig = plt.figure()
152151

153-
ax = fig.add_subplot(111)
152+
fig, ax = plt.subplots()
154153
ax.xaxis.set_animated(True)
155154
ax.yaxis.set_animated(True)
156155
canvas = fig.canvas

examples/animation/old_animation/animation_blit_tk.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
matplotlib.use('TkAgg')
88

99
import sys
10-
import pylab as p
10+
import matplotlib.pyplot as plt
1111
import numpy as npy
1212
import time
1313

14-
ax = p.subplot(111)
15-
canvas = ax.figure.canvas
14+
fig, ax = plt.subplots()
15+
canvas = fig.canvas
1616

1717

1818
# create the initial line
1919
x = npy.arange(0,2*npy.pi,0.01)
20-
line, = p.plot(x, npy.sin(x), animated=True, lw=2)
20+
line, = plt.plot(x, npy.sin(x), animated=True, lw=2)
2121

2222
def run(*args):
2323
background = canvas.copy_from_bbox(ax.bbox)
@@ -43,12 +43,12 @@ def run(*args):
4343
run.cnt = 0
4444

4545

46-
p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
47-
p.grid() # to ensure proper background restore
48-
manager = p.get_current_fig_manager()
46+
plt.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
47+
plt.grid() # to ensure proper background restore
48+
manager = plt.get_current_fig_manager()
4949
manager.window.after(100, run)
5050

51-
p.show()
51+
plt.show()
5252

5353

5454

examples/animation/old_animation/animation_blit_wx.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import matplotlib
1111
matplotlib.use('WXAgg')
1212
matplotlib.rcParams['toolbar'] = 'None'
13+
import matplotlib.pyplot as plt
1314

1415
import wx
1516
import sys
@@ -24,8 +25,8 @@
2425
matplotlib.backends.backend_wxagg._use_accelerator(False)
2526

2627

27-
ax = p.subplot(111)
28-
canvas = ax.figure.canvas
28+
fig, ax = plt.subplots()
29+
canvas = fig.canvas
2930

3031

3132
p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs

examples/animation/old_animation/draggable_legend.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import matplotlib.pyplot as plt
22

3-
4-
ax = plt.subplot(111)
3+
fig, ax = plt.subplots()
54
ax.plot([1,2,3], label="test")
65

76
l = ax.legend()
87
d1 = l.draggable()
98

10-
xy = 1, 2
9+
xy = 1, 2
1110
txt = ax.annotate("Test", xy, xytext=(-30, 30),
1211
textcoords="offset points",
1312
bbox=dict(boxstyle="round",fc=(0.2, 1, 1)),

0 commit comments

Comments
 (0)