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

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)),

examples/animation/old_animation/gtk_timeout.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
import matplotlib.pyplot as plt
77

8-
fig = plt.figure()
9-
ax = fig.add_subplot(111)
8+
fig, ax = plt.subplots()
109
line, = ax.plot(np.random.rand(10))
1110
ax.set_ylim(0, 1)
1211

examples/animation/old_animation/histogram_tkagg.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
This example shows how to use a path patch to draw a bunch of
33
rectangles for an animated histogram
44
"""
5-
import time
65
import numpy as np
76
import matplotlib
87
matplotlib.use('TkAgg') # do this before importing pylab
@@ -11,8 +10,7 @@
1110
import matplotlib.patches as patches
1211
import matplotlib.path as path
1312

14-
fig = plt.figure()
15-
ax = fig.add_subplot(111)
13+
fig, ax = plt.subplots()
1614

1715
# histogram our data with numpy
1816
data = np.random.randn(1000)

examples/animation/old_animation/simple_anim_gtk.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
import matplotlib.pyplot as plt
1111

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

1614
def animate():
1715
tstart = time.time() # for profiling

examples/animation/old_animation/simple_anim_tkagg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
matplotlib.use('TkAgg') # do this before importing pylab
1111

1212
import matplotlib.pyplot as plt
13-
fig = plt.figure()
14-
ax = fig.add_subplot(111)
13+
fig, ax = plt.subplots()
1514

1615
def animate():
1716
tstart = time.time() # for profiling

examples/animation/old_animation/simple_idle_wx.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22
A simple example of an animated plot using a wx backend
33
"""
44
from __future__ import print_function
5-
import time
65
import numpy as np
76
import matplotlib
87
matplotlib.use('WXAgg') # do this before importing pylab
98

109
import matplotlib.pyplot as plt
1110

12-
fig = plt.figure()
13-
14-
ax = fig.add_subplot(111)
11+
fig, ax = plt.subplots()
1512
t = np.arange(0, 2*np.pi, 0.1)
1613
line, = ax.plot(t, np.sin(t))
1714
dt = 0.05

examples/animation/old_animation/simple_timer_wx.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22
"""
33
A simple example of an animated plot using a wx backend
44
"""
5-
import time
65
import numpy as np
76
import matplotlib
87
matplotlib.use('WXAgg') # do this before importing pylab
98

109
import matplotlib.pyplot as plt
1110

12-
fig = plt.figure()
13-
14-
ax = fig.add_subplot(111)
11+
fig, ax = plt.subplots()
1512
t = np.arange(0, 2*np.pi, 0.1)
1613
line, = ax.plot(t, np.sin(t))
1714
dt = 0.05

examples/animation/old_animation/strip_chart_demo.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import matplotlib
1414
matplotlib.use('GTKAgg')
1515
import numpy as np
16+
import matplotlib.pyplot as plt
1617
from matplotlib.lines import Line2D
1718

1819

@@ -62,11 +63,8 @@ def update(self, *args):
6263
return True
6364

6465

65-
from pylab import figure, show
66-
67-
fig = figure()
68-
ax = fig.add_subplot(111)
66+
fig, ax = plt.subplots()
6967
scope = Scope(ax)
7068
gobject.idle_add(scope.update)
7169

72-
show()
70+
plt.show()

examples/animation/random_data.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import matplotlib.pyplot as plt
33
import matplotlib.animation as animation
44

5-
fig = plt.figure()
6-
ax = fig.add_subplot(111)
5+
fig, ax = plt.subplots()
76
line, = ax.plot(np.random.rand(10))
87
ax.set_ylim(0, 1)
98

examples/animation/simple_anim.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import matplotlib.pyplot as plt
66
import matplotlib.animation as animation
77

8-
fig = plt.figure()
9-
ax = fig.add_subplot(111)
8+
fig, ax = plt.subplots()
109

1110
x = np.arange(0, 2*np.pi, 0.01) # x-array
1211
line, = ax.plot(x, np.sin(x))

examples/animation/strip_chart_demo.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Emulate an oscilloscope. Requires the animation API introduced in
33
matplotlib 1.0 SVN.
44
"""
5-
import matplotlib
65
import numpy as np
76
from matplotlib.lines import Line2D
87
import matplotlib.pyplot as plt
@@ -44,8 +43,7 @@ def emitter(p=0.03):
4443
else:
4544
yield np.random.rand(1)
4645

47-
fig = plt.figure()
48-
ax = fig.add_subplot(111)
46+
fig, ax = plt.subplots()
4947
scope = Scope(ax)
5048

5149
# pass a generator in "emitter" to produce data for the update func

examples/api/README.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ A simple example of the recommended style is::
2929
import numpy as np
3030
import matplotlib.pyplot as plt
3131

32-
fig = plt.figure()
33-
ax = fig.add_subplot(111) # or add_axes
32+
fig, ax = plt.subplots()
3433
ax.plot(np.random.rand(10))
3534
ax.set_xlabel('some x data')
3635
ax.set_ylabel('some y data')

examples/api/barchart_demo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
ind = np.arange(N) # the x locations for the groups
1212
width = 0.35 # the width of the bars
1313

14-
fig = plt.figure()
15-
ax = fig.add_subplot(111)
14+
fig, ax = plt.subplots()
1615
rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)
1716

1817
womenMeans = (25, 32, 34, 20, 25)

0 commit comments

Comments
 (0)