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

Skip to content

Commit 32eb2c5

Browse files
authored
Merge pull request #6957 from phobson/partial-update-pylab-examples
DOC: clearing out some instances of using pylab in the docs
2 parents bb93047 + 3e25df7 commit 32eb2c5

File tree

6 files changed

+71
-75
lines changed

6 files changed

+71
-75
lines changed

doc/faq/installing_faq.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ complexities. Open up a UNIX shell or a DOS command prompt and cd into a
2323
directory containing a minimal example in a file. Something like
2424
:file:`simple_plot.py` for example::
2525

26-
from pylab import *
27-
plot([1,2,3])
28-
show()
26+
import matplotlib.pyplot as plt
27+
fig, ax = plt.subplots()
28+
ax.plot([1,2,3])
29+
plt.show()
2930

3031
and run it with::
3132

doc/pyplots/boxplot_demo.py

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,60 @@
44
# Example boxplot code
55
#
66

7-
from pylab import *
7+
import numpy as np
8+
import matplotlib.pyplot as plt
89

9-
# fake up some data
10-
spread= rand(50) * 100
11-
center = ones(25) * 50
12-
flier_high = rand(10) * 100 + 100
13-
flier_low = rand(10) * -100
14-
data =concatenate((spread, center, flier_high, flier_low), 0)
15-
16-
# basic plot
17-
boxplot(data)
18-
#savefig('box1')
19-
20-
# notched plot
21-
figure()
22-
boxplot(data,1)
23-
#savefig('box2')
24-
25-
# change outlier point symbols
26-
figure()
27-
boxplot(data,0,'gD')
28-
#savefig('box3')
29-
30-
# don't show outlier points
31-
figure()
32-
boxplot(data,0,'')
33-
#savefig('box4')
10+
np.random.seed(0)
3411

35-
# horizontal boxes
36-
figure()
37-
boxplot(data,0,'rs',0)
38-
#savefig('box5')
39-
40-
# change whisker length
41-
figure()
42-
boxplot(data,0,'rs',0,0.75)
43-
#savefig('box6')
12+
# fake up some data
13+
spread = np.random.rand(50) * 100
14+
center = np.ones(25) * 50
15+
flier_high = np.random.rand(10) * 100 + 100
16+
flier_low = np.random.rand(10) * -100
17+
data = np.concatenate((spread, center, flier_high, flier_low), 0)
18+
19+
fig1, ax1 = plt.subplots()
20+
ax1.set_title('Basic Plot')
21+
ax1.boxplot(data)
22+
23+
fig2, ax2 = plt.subplots()
24+
ax2.set_title('Notched boxes')
25+
ax2.boxplot(data, notch=True)
26+
27+
green_diamond = dict(markerfacecolor='g', marker='D')
28+
fig3, ax3 = plt.subplots()
29+
ax3.set_title('Changed Outlier Symbols')
30+
ax3.boxplot(data, flierprops=green_diamond)
31+
32+
fig4, ax4 = plt.subplots()
33+
ax4.set_title('Hide Outlier Points')
34+
ax4.boxplot(data, showfliers=False)
35+
36+
red_square = dict(markerfacecolor='r', marker='s')
37+
fig5, ax5 = plt.subplots()
38+
ax5.set_title('Horizontal Boxes')
39+
ax5.boxplot(data, vert=False, flierprops=red_square)
40+
41+
fig6, ax6 = plt.subplots()
42+
ax6.set_title('Shorter Whisker Length')
43+
ax6.boxplot(data, flierprops=red_square, vert=False, whis=0.75)
4444

4545
# fake up some more data
46-
spread= rand(50) * 100
47-
center = ones(25) * 40
48-
flier_high = rand(10) * 100 + 100
49-
flier_low = rand(10) * -100
50-
d2 = concatenate( (spread, center, flier_high, flier_low), 0 )
46+
spread = np.random.rand(50) * 100
47+
center = np.ones(25) * 40
48+
flier_high = np.random.rand(10) * 100 + 100
49+
flier_low = np.random.rand(10) * -100
50+
d2 = np.concatenate((spread, center, flier_high, flier_low), 0)
5151
data.shape = (-1, 1)
5252
d2.shape = (-1, 1)
53-
#data = concatenate( (data, d2), 1 )
53+
5454
# Making a 2-D array only works if all the columns are the
5555
# same length. If they are not, then use a list instead.
5656
# This is actually more efficient because boxplot converts
5757
# a 2-D array into a list of vectors internally anyway.
5858
data = [data, d2, d2[::2,0]]
59-
# multiple box plots on one figure
60-
figure()
61-
boxplot(data)
62-
#savefig('box7')
63-
64-
show()
59+
fig7, ax7 = plt.subplots()
60+
ax7.set_title('Multiple Samples with Different sizes')
61+
ax7.boxplot(data)
6562

63+
plt.show()
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#!/usr/bin/env python
22
import matplotlib.mlab as mlab
3-
from pylab import figure, show
3+
import matplotlib.pyplot as plt
44
import numpy as np
55

66
x = np.arange(0.0, 2, 0.01)
77
y1 = np.sin(2*np.pi*x)
88
y2 = 1.2*np.sin(4*np.pi*x)
99

10-
fig = figure()
11-
ax = fig.add_subplot(111)
10+
fig, ax = plt.subplots()
1211
ax.plot(x, y1, x, y2, color='black')
1312
ax.fill_between(x, y1, y2, where=y2>y1, facecolor='green')
1413
ax.fill_between(x, y1, y2, where=y2<=y1, facecolor='red')
1514
ax.set_title('fill between where')
1615

17-
show()
16+
plt.show()

doc/pyplots/whats_new_99_mplot3d.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
from mpl_toolkits.mplot3d import Axes3D
2-
from matplotlib import cm
3-
import pylab
41
import random
2+
53
import numpy as np
4+
import matplotlib.pyplot as plt
5+
from matplotlib import cm
6+
from mpl_toolkits.mplot3d import Axes3D
67

7-
fig = pylab.figure()
8-
ax = Axes3D(fig)
98
X = np.arange(-5, 5, 0.25)
109
Y = np.arange(-5, 5, 0.25)
1110
X, Y = np.meshgrid(X, Y)
1211
R = np.sqrt(X**2 + Y**2)
1312
Z = np.sin(R)
14-
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet)
1513

16-
pylab.show()
14+
fig = plt.figure()
15+
ax = Axes3D(fig)
16+
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.viridis)
1717

18+
plt.show()

examples/api/colorbar_only.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
Make a colorbar as a separate figure.
33
'''
44

5-
from matplotlib import pyplot
5+
import matplotlib.pyplot as plt
66
import matplotlib as mpl
77

88
# Make a figure and axes with dimensions as desired.
9-
fig = pyplot.figure(figsize=(8, 3))
9+
fig = plt.figure(figsize=(8, 3))
1010
ax1 = fig.add_axes([0.05, 0.80, 0.9, 0.15])
1111
ax2 = fig.add_axes([0.05, 0.475, 0.9, 0.15])
1212
ax3 = fig.add_axes([0.05, 0.15, 0.9, 0.15])
@@ -71,4 +71,4 @@
7171
orientation='horizontal')
7272
cb3.set_label('Custom extension lengths, some other units')
7373

74-
pyplot.show()
74+
plt.show()

examples/units/units_scatter.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,25 @@
99
arrays.
1010
"""
1111
import numpy as np
12+
import matplotlib.pyplot as plt
1213
from basic_units import secs, hertz, minutes
13-
from matplotlib.pylab import figure, show
1414

1515
# create masked array
16+
data = (1, 2, 3, 4, 5, 6, 7, 8)
17+
mask = (1, 0, 1, 0, 0, 0, 1, 0)
18+
xsecs = secs * np.ma.MaskedArray(data, mask, float)
1619

17-
18-
xsecs = secs*np.ma.MaskedArray((1, 2, 3, 4, 5, 6, 7, 8), (1, 0, 1, 0, 0, 0, 1, 0), float)
19-
#xsecs = secs*np.arange(1,10.)
20-
21-
fig = figure()
22-
ax1 = fig.add_subplot(3, 1, 1)
20+
fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, sharex=True)
2321
ax1.scatter(xsecs, xsecs)
24-
#ax1.set_ylabel('seconds')
22+
ax1.yaxis.set_units(secs)
2523
ax1.axis([0, 10, 0, 10])
2624

27-
ax2 = fig.add_subplot(3, 1, 2, sharex=ax1)
2825
ax2.scatter(xsecs, xsecs, yunits=hertz)
2926
ax2.axis([0, 10, 0, 1])
3027

31-
ax3 = fig.add_subplot(3, 1, 3, sharex=ax1)
3228
ax3.scatter(xsecs, xsecs, yunits=hertz)
3329
ax3.yaxis.set_units(minutes)
3430
ax3.axis([0, 10, 0, 1])
3531

36-
show()
32+
fig.tight_layout()
33+
plt.show()

0 commit comments

Comments
 (0)