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

Skip to content

Commit 63d743d

Browse files
committed
Merge pull request #4685 from domspad/MEP-on-barchart_demo2.py
MEP12-on-barchart_demo2.py
2 parents 7bcea7a + df4ab53 commit 63d743d

File tree

5 files changed

+44
-52
lines changed

5 files changed

+44
-52
lines changed

examples/pylab_examples/barchart_demo2.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"""
1111
import numpy as np
1212
import matplotlib.pyplot as plt
13-
import pylab
1413
from matplotlib.ticker import MaxNLocator
1514

1615
student = 'Johnny Doe'
@@ -33,7 +32,7 @@
3332
rects = ax1.barh(pos, rankings, align='center', height=0.5, color='m')
3433

3534
ax1.axis([0, 100, 0, 5])
36-
pylab.yticks(pos, testNames)
35+
plt.yticks(pos, testNames)
3736
ax1.set_title('Johnny Doe')
3837
plt.text(50, -0.5, 'Cohort Size: ' + str(cohortSize),
3938
horizontalalignment='center', size='small')
@@ -43,7 +42,7 @@
4342
ax2 = ax1.twinx()
4443
ax2.plot([100, 100], [0, 5], 'white', alpha=0.1)
4544
ax2.xaxis.set_major_locator(MaxNLocator(11))
46-
xticks = pylab.setp(ax2, xticklabels=['0', '10', '20', '30', '40', '50', '60',
45+
xticks = plt.setp(ax2, xticklabels=['0', '10', '20', '30', '40', '50', '60',
4746
'70', '80', '90', '100'])
4847
ax2.xaxis.grid(True, linestyle='--', which='major', color='grey',
4948
alpha=0.25)
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
from matplotlib.pyplot import figure, show, cm
2-
from numpy import where
3-
from numpy.random import rand
1+
import matplotlib.pyplot as plt
2+
import numpy as np
43

54
# the bar
6-
x = where(rand(500) > 0.7, 1.0, 0.0)
5+
x = np.where(np.random.rand(500) > 0.7, 1.0, 0.0)
76

87
axprops = dict(xticks=[], yticks=[])
9-
barprops = dict(aspect='auto', cmap=cm.binary, interpolation='nearest')
8+
barprops = dict(aspect='auto', cmap=plt.cm.binary, interpolation='nearest')
109

11-
fig = figure()
10+
fig = plt.figure()
1211

1312
# a vertical barcode -- this is broken at present
1413
x.shape = len(x), 1
@@ -22,4 +21,4 @@
2221
ax.imshow(x, **barprops)
2322

2423

25-
show()
24+
plt.show()
Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,52 @@
1-
#!/usr/bin/python
2-
3-
#
4-
# Example boxplot code
5-
#
6-
7-
from pylab import *
1+
import matplotlib.pyplot as plt
2+
import numpy as np
83

94
# 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)
5+
spread = np.random.rand(50) * 100
6+
center = np.ones(25) * 50
7+
flier_high = np.random.rand(10) * 100 + 100
8+
flier_low = np.random.rand(10) * -100
9+
data = np.concatenate((spread, center, flier_high, flier_low), 0)
1510

1611
# basic plot
17-
boxplot(data)
12+
plt.boxplot(data)
1813

1914
# notched plot
20-
figure()
21-
boxplot(data, 1)
15+
plt.figure()
16+
plt.boxplot(data, 1)
2217

2318
# change outlier point symbols
24-
figure()
25-
boxplot(data, 0, 'gD')
19+
plt.figure()
20+
plt.boxplot(data, 0, 'gD')
2621

2722
# don't show outlier points
28-
figure()
29-
boxplot(data, 0, '')
23+
plt.figure()
24+
plt.boxplot(data, 0, '')
3025

3126
# horizontal boxes
32-
figure()
33-
boxplot(data, 0, 'rs', 0)
27+
plt.figure()
28+
plt.boxplot(data, 0, 'rs', 0)
3429

3530
# change whisker length
36-
figure()
37-
boxplot(data, 0, 'rs', 0, 0.75)
31+
plt.figure()
32+
plt.boxplot(data, 0, 'rs', 0, 0.75)
3833

3934
# fake up some more data
40-
spread = rand(50) * 100
41-
center = ones(25) * 40
42-
flier_high = rand(10) * 100 + 100
43-
flier_low = rand(10) * -100
44-
d2 = concatenate((spread, center, flier_high, flier_low), 0)
35+
spread = np.random.rand(50) * 100
36+
center = np.ones(25) * 40
37+
flier_high = np.random.rand(10) * 100 + 100
38+
flier_low = np.random.rand(10) * -100
39+
d2 = np.concatenate((spread, center, flier_high, flier_low), 0)
4540
data.shape = (-1, 1)
4641
d2.shape = (-1, 1)
47-
#data = concatenate( (data, d2), 1 )
42+
# data = concatenate( (data, d2), 1 )
4843
# Making a 2-D array only works if all the columns are the
4944
# same length. If they are not, then use a list instead.
5045
# This is actually more efficient because boxplot converts
5146
# a 2-D array into a list of vectors internally anyway.
5247
data = [data, d2, d2[::2, 0]]
5348
# multiple box plots on one figure
54-
figure()
55-
boxplot(data)
49+
plt.figure()
50+
plt.boxplot(data)
5651

57-
show()
52+
plt.show()

examples/pylab_examples/break.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#!/usr/bin/env python
2-
from pylab import *
1+
import matplotlib.pyplot as plt
32

3+
plt.gcf().text(0.5, 0.95, 'Distance Histograms by Category is \
4+
a really long title')
45

5-
gcf().text(0.5, 0.95,
6-
'Distance Histograms by Category is a really long title')
7-
8-
show()
6+
plt.show()

examples/pylab_examples/clippedline.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
"""
1010

1111
from matplotlib.lines import Line2D
12+
import matplotlib.pyplot as plt
1213
import numpy as np
13-
from pylab import figure, show
1414

1515

1616
class ClippedLine(Line2D):
1717
"""
18-
Clip the xlimits to the axes view limits -- this example assumes x is sorted
18+
Clip the xlimits to the axes view limits
19+
this example assumes x is sorted
1920
"""
2021

2122
def __init__(self, ax, *args, **kwargs):
@@ -45,7 +46,7 @@ def draw(self, renderer):
4546
Line2D.draw(self, renderer)
4647

4748

48-
fig = figure()
49+
fig = plt.figure()
4950
ax = fig.add_subplot(111, autoscale_on=False)
5051

5152
t = np.arange(0.0, 100.0, 0.01)
@@ -54,4 +55,4 @@ def draw(self, renderer):
5455
ax.add_line(line)
5556
ax.set_xlim(10, 30)
5657
ax.set_ylim(-1.1, 1.1)
57-
show()
58+
plt.show()

0 commit comments

Comments
 (0)