8000 Merge remote-tracking branch 'matplotlib/master' · matplotlib/matplotlib@dab776c · GitHub
[go: up one dir, main page]

Skip to content

Commit dab776c

Browse files
committed
Merge remote-tracking branch 'matplotlib/master'
2 parents 09f2577 + 37f7df6 commit dab776c

File tree

14 files changed

+172
-93
lines changed

14 files changed

+172
-93
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Removed `Lena` images from sample_data
2+
``````````````````````````````````````
3+
4+
The ``lena.png`` and ``lena.jpg`` images have been removed from
5+
matplotlibs sample_data directory. The images are also no longer
6+
available from `matplotlib.cbook.get_sample_data`. We suggest using
7+
`matplotlib.cbook.get_sample_data('grace_hopper.png')` or
8+
`matplotlib.cbook.get_sample_data('grace_hopper.jpg')` instead.
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
# use masked arrays to plot a line with different colors by y-value
2-
from numpy import logical_or, arange, sin, pi
3-
from numpy import ma
4-
from matplotlib.pyplot import plot, show
2+
import numpy as np
3+
import matplotlib.pyplot as plt
54

6-
t = arange(0.0, 2.0, 0.01)
7-
s = sin(2*pi*t)
5+
t = np.arange(0.0, 2.0, 0.01)
6+
s = np.sin(2*np.pi*t)
87

98
upper = 0.77
109
lower = -0.77
1110

1211

13-
supper = ma.masked_where(s < upper, s)
14-
slower = ma.masked_where(s > lower, s)
15-
smiddle = ma.masked_where(logical_or(s < lower, s > upper), s)
12+
supper = np.ma.masked_where(s < upper, s)
13+
slower = np.ma.masked_where(s > lower, s)
14+
smiddle = np.ma.masked_where(np.logical_or(s < lower, s > upper), s)
1615

17-
plot(t, slower, 'r', t, smiddle, 'b', t, supper, 'g')
18-
show()
16+
plt.plot(t, slower, 'r', t, smiddle, 'b', t, supper, 'g')
17+
plt.show()

examples/pylab_examples/color_demo.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
1414
See help(colors) for more info.
1515
"""
16-
from pylab import *
16+
import matplotlib.pyplot as plt
17+
import numpy as np
1718

18-
subplot(111, axisbg='darkslategray')
19+
plt.subplot(111, axisbg='darkslategray')
1920
#subplot(111, axisbg='#ababab')
20-
t = arange(0.0, 2.0, 0.01)
21-
s = sin(2*pi*t)
22-
plot(t, s, 'y')
23-
xlabel('time (s)', color='r')
24-
ylabel('voltage (mV)', color='0.5') # grayscale color
25-
title('About as silly as it gets, folks', color='#afeeee')
26-
show()
21+
t = np.arange(0.0, 2.0, 0.01)
22+
s = np.sin(2*np.pi*t)
23+
plt.plot(t, s, 'y')
24+
plt.xlabel('time (s)', color='r')
25+
plt.ylabel('voltage (mV)', color='0.5') # grayscale color
26+
plt.title('About as silly as it gets, folks', color='#afeeee')
27+
plt.show()

examples/pylab_examples/contour_image.py

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,34 @@
88
desired. In particular, note the usage of the "origin" and "extent"
99
keyword arguments to imshow and contour.
1010
'''
11-
from pylab import *
11+
import matplotlib.pyplot as plt
12+
import numpy as np
13+
from matplotlib import mlab, cm
1214

1315
# Default delta is large because that makes it fast, and it illustrates
1416
# the correct registration between image and contours.
1517
delta = 0.5
1618

1719
extent = (-3, 4, -4, 3)
1820

19-
x = arange(-3.0, 4.001, delta)
20-
y = arange(-4.0, 3.001, delta)
21-
X, Y = meshgrid(x, y)
22-
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
23-
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
21+
x = np.arange(-3.0, 4.001, delta)
22+
y = np.arange(-4.0, 3.001, delta)
23+
X, Y = np.meshgrid(x, y)
24+
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
25+
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
2426
Z = (Z1 - Z2) * 10
2527

26-
levels = arange(-2.0, 1.601, 0.4) # Boost the upper limit to avoid truncation errors.
28+
levels = np.arange(-2.0, 1.601, 0.4) # Boost the upper limit to avoid truncation errors.
2729

2830
norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())
2931
cmap = cm.PRGn
3032

31-
figure()
33+
plt.figure()
3234

3335

34-
subplot(2, 2, 1)
36+
plt.subplot(2, 2, 1)
3537

36-
cset1 = contourf(X, Y, Z, levels,
38+
cset1 = plt.contourf(X, Y, Z, levels,
3739
cmap=cm.get_cmap(cmap, len(levels) - 1),
3840
norm=norm,
3941
)
@@ -45,7 +47,7 @@
4547
# contour separately; don't try to change the edgecolor or edgewidth
4648
# of the polygons in the collections returned by contourf.
4749
# Use levels output from previous call to guarantee they are the same.
48-
cset2 = contour(X, Y, Z, cset1.levels,
50+
cset2 = plt.contour(X, Y, Z, cset1.levels,
4951
colors='k',
5052
hold='on')
5153
# We don't really need dashed contour lines to indicate negative
@@ -57,49 +59,49 @@
5759
# to set up an array of colors and linewidths.
5860
# We are making a thick green line as a zero contour.
5961
# Specify the zero level as a tuple with only 0 in it.
60-
cset3 = contour(X, Y, Z, (0,),
62+
cset3 = plt.contour(X, Y, Z, (0,),
6163
colors='g',
6264
linewidths=2,
6365
hold='on')
64-
title('Filled contours')
65-
colorbar(cset1)
66+
plt.title('Filled contours')
67+
plt.colorbar(cset1)
6668
#hot()
6769

6870

69-
subplot(2, 2, 2)
71+
plt.subplot(2, 2, 2)
7072

71-
imshow(Z, extent=extent, cmap=cmap, norm=norm)
72-
v = axis()
73-
contour(Z, levels, hold='on', colors='k',
73+
plt.imshow(Z, extent=extent, cmap=cmap, norm=norm)
74+
v = plt.axis()
75+
plt.contour(Z, levels, hold='on', colors='k',
7476
origin='upper', extent=extent)
75-
axis(v)
76-
title("Image, origin 'upper'")
77+
plt.axis(v)
78+
plt.title("Image, origin 'upper'")
7779

78-
subplot(2, 2, 3)
80+
plt.subplot(2, 2, 3)
7981

80-
imshow(Z, origin='lower', extent=extent, cmap=cmap, norm=norm)
81-
v = axis()
82-
contour(Z, levels, hold='on', colors='k',
82+
plt.imshow(Z, origin='lower', extent=extent, cmap=cmap, norm=norm)
83+
v = plt.axis()
84+
plt.contour(Z, levels, hold='on', colors='k',
8385
origin='lower', extent=extent)
84-
axis(v)
85-
title("Image, origin 'lower'")
86+
plt.axis(v)
87+
plt.title("Image, origin 'lower'")
8688

87-
subplot(2, 2, 4)
89+
plt.subplot(2, 2, 4)
8890

8991
# We will use the interpolation "nearest" here to show the actual
9092
# image pixels.
9193
# Note that the contour lines don't extend to the edge of the box.
9294
# This is intentional. The Z values are defined at the center of each
9395
# image pixel (each color block on the following subplot), so the
9496
# domain that is contoured does not extend beyond these pixel centers.
95-
im = imshow(Z, interpolation='nearest', extent=extent, cmap=cmap, norm=norm)
96-
v = axis()
97-
contour(Z, levels, hold='on', colors='k',
97+
im = plt.imshow(Z, interpolation='nearest', extent=extent, cmap=cmap, norm=norm)
98+
v = plt.axis()
99+
plt.contour(Z, levels, hold='on', colors='k',
98100
origin='image', extent=extent)
99-
axis(v)
100-
ylim = get(gca(), 'ylim')
101-
setp(gca(), ylim=ylim[::-1])
102-
title("Image, origin from rc, reversed y-axis")
103-
colorbar(im)
101+
plt.axis(v)
102+
ylim = plt.get(plt.gca(), 'ylim')
103+
plt.setp(plt.gca(), ylim=ylim[::-1])
104+
plt.title("Image, origin from rc, reversed y-axis")
105+
plt.colorbar(im)
104106

105-
show()
107+
plt.show()

examples/pylab_examples/coords_demo.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
"""
77
from __future__ import print_function
88
import sys
9-
from pylab import *
9+
import matplotlib.pyplot as plt
10+
import numpy as np
1011

11-
t = arange(0.0, 1.0, 0.01)
12-
s = sin(2*pi*t)
12+
t = np.arange(0.0, 1.0, 0.01)
13+
s = np.sin(2*np.pi*t)
1314
fig, ax = plt.subplots()
1415
ax.plot(t, s)
1516

@@ -30,11 +31,11 @@ def on_click(event):
3031
if event.inaxes is not None:
3132
print('data coords %f %f' % (event.xdata, event.ydata))
3233

33-
binding_id = connect('motion_notify_event', on_move)
34-
connect('button_press_event', on_click)
34+
binding_id = plt.connect('motion_notify_event', on_move)
35+
plt.connect('button_press_event', on_click)
3536

3637
if "test_disconnect" in sys.argv:
3738
print("disconnecting console coordinate printout...")
38-
disconnect(binding_id)
39+
plt.disconnect(binding_id)
3940

40-
show()
41+
plt.show()

examples/pylab_examples/coords_report.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
# override the default reporting of coords
44

5-
from pylab import *
5+
import matplotlib.pyplot as plt
6+
import numpy as np
67

78

89
def millions(x):
910
return '$%1.1fM' % (x*1e-6)
1011

11-
x = rand(20)
12-
y = 1e7*rand(20)
12+
x = np.random.rand(20)
13+
y = 1e7*np.random.rand(20)
1314

14-
fig, ax = subplots()
15+
fig, ax = plt.subplots()
1516
ax.fmt_ydata = millions
16-
plot(x, y, 'o')
17+
plt.plot(x, y, 'o')
1718

18-
show()
19+
plt.show()
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
1-
from pylab import *
1+
import matplotlib.pyplot as plt
2+
import numpy as np
23
from matplotlib.collections import LineCollection
34

45
# In order to efficiently plot many lines in a single set of axes,
56
# Matplotlib has the ability to add the lines all at once. Here is a
67
# simple example showing how it is done.
78

89
N = 50
9-
x = arange(N)
10+
x = np.arange(N)
1011
# Here are many sets of y to plot vs x
1112
ys = [x + i for i in x]
1213

1314
# We need to set the plot limits, they will not autoscale
14-
ax = axes()
15-
ax.set_xlim((amin(x), amax(x)))
16-
ax.set_ylim((amin(amin(ys)), amax(amax(ys))))
15+
ax = plt.axes()
16+
ax.set_xlim((np.amin(x), np.amax(x)))
17+
ax.set_ylim((np.amin(np.amin(ys)), np.amax(np.amax(ys))))
1718

1819
# colors is sequence of rgba tuples
1920
# linestyle is a string or dash tuple. Legal string values are
2021
# solid|dashed|dashdot|dotted. The dash tuple is (offset, onoffseq)
2122
# where onoffseq is an even length tuple of on and off ink in points.
2223
# If linestyle is omitted, 'solid' is used
2324
# See matplotlib.collections.LineCollection for more information
24-
line_segments = LineCollection([list(zip(x, y)) for y in ys], # Make a sequence of x,y pairs
25+
26+
# Make a sequence of x,y pairs
27+
line_segments = LineCollection([list(zip(x, y)) for y in ys],
2528
linewidths=(0.5, 1, 1.5, 2),
2629
linestyles='solid')
2730
line_segments.set_array(x)
2831
ax.add_collection(line_segments)
29-
fig = gcf()
32+
fig = plt.gcf()
3033
axcb = fig.colorbar(line_segments)
3134
axcb.set_label('Line Number')
3235
ax.set_title('Line Collection with mapped colors')
33-
sci(line_segments) # This allows interactive changing of the colormap.
34-
show()
36+
plt.sci(line_segments) # This allows interactive changing of the colormap.
37+
plt.show()
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
from __future__ import print_function
2-
from matplotlib.dates import bytespdate2num
3-
#from matplotlib.mlab import load
42
import numpy as np
5-
from pylab import figure, show
3+
import matplotlib.pyplot as plt
64
import matplotlib.cbook as cbook
5+
import matplotlib.dates as mdates
6+
from matplotlib.dates import bytespdate2num
77

88
datafile = cbook.get_sample_data('msft.csv', asfileobj=False)
99
print('loading', datafile)
1010

11-
dates, closes = np.loadtxt(
12-
datafile, delimiter=',',
13-
converters={0: bytespdate2num('%d-%b-%y')},
14-
skiprows=1, usecols=(0, 2), unpack=True)
11+
dates, closes = np.loadtxt(datafile, delimiter=',',
12+
converters={0: bytespdate2num('%d-%b-%y')},
13+
skiprows=1, usecols=(0, 2), unpack=True)
1514

16-
fig = figure()
15+
fig = plt.figure()
1716
ax = fig.add_subplot(111)
1817
ax.plot_date(dates, closes, '-')
1918
fig.autofmt_xdate()
20-
show()
19+
plt.show()

examples/pylab_examples/loadrec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import print_function
22
from matplotlib import mlab
3-
from pylab import figure, show
3+
import matplotlib.pyplot as plt
44
import matplotlib.cbook as cbook
55

66
datafile = cbook.get_sample_data('msft.csv', asfileobj=False)
@@ -9,7 +9,7 @@
99
a.sort()
1010
print(a.dtype)
1111

12-
fig = figure()
12+
fig = plt.figure()
1313
ax = fig.add_subplot(111)
1414
ax.plot(a.date, a.adj_close, '-')
1515
fig.autofmt_xdate()
@@ -20,4 +20,4 @@
2020
exceltools.rec2excel(a, 'test.xls')
2121
except ImportError:
2222
pass
23-
show()
23+
plt.show()

0 commit comments

Comments
 (0)
0