8000 Use standard NumPy import in pylab examples. · matplotlib/matplotlib@2b9e2d1 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2b9e2d1

Browse files
committed
Use standard NumPy import in pylab examples.
1 parent 1144e8c commit 2b9e2d1

File tree

12 files changed

+40
-40
lines changed

12 files changed

+40
-40
lines changed

examples/animation/image_slices_viewer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
66
"""
77
from __future__ import print_function
8-
import numpy
8+
9+
import numpy as np
910
import matplotlib.pyplot as plt
1011

1112

@@ -24,9 +25,9 @@ def __init__(self, ax, X):
2425
def onscroll(self, event):
2526
print("%s %s" % (event.button, event.step))
2627
if event.button == 'up':
27-
self.ind = numpy.clip(self.ind + 1, 0, self.slices - 1)
28+
self.ind = np.clip(self.ind + 1, 0, self.slices - 1)
2829
else:
29-
self.ind = numpy.clip(self.ind - 1, 0, self.slices - 1)
30+
self.ind = np.clip(self.ind - 1, 0, self.slices - 1)
3031
self.update()
3132

3233
def update(self):
@@ -37,7 +38,7 @@ def update(self):
3738

3839
fig, ax = plt.subplots(1, 1)
3940

40-
X = numpy.random.rand(20, 20, 40)
41+
X = np.random.rand(20, 20, 40)
4142

4243
tracker = IndexTracker(ax, X)
4344

examples/event_handling/pick_event_demo2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
mean vs stddev. When you click on one of the mu, sigma points, plot the raw
88
data from the dataset that generated the mean and stddev.
99
"""
10-
import numpy
10+
import numpy as np
1111
import matplotlib.pyplot as plt
1212

1313

14-
X = numpy.random.rand(100, 1000)
15-
xs = numpy.mean(X, axis=1)
16-
ys = numpy.std(X, axis=1)
14+
X = np.random.rand(100, 1000)
15+
xs = np.mean(X, axis=1)
16+
ys = np.std(X, axis=1)
1717

1818
fig, ax = plt.subplots()
1919
ax.set_title('click on point to plot time series')

examples/event_handling/zoom_window.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
points**2, so their size is independent of the zoom
1515
"""
1616
from matplotlib.pyplot import figure, show
17-
import numpy
17+
import numpy as np
1818
figsrc = figure()
1919
figzoom = figure()
2020

@@ -23,7 +23,7 @@
2323
autoscale_on=False)
2424
axsrc.set_title('Click to zoom')
2525
axzoom.set_title('zoom window')
26-
x, y, s, c = numpy.random.rand(4, 200)
26+
x, y, s, c = np.random.rand(4, 200)
2727
s *= 200
2828

2929

examples/pylab_examples/ellipse_demo.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55
66
"""
77
import matplotlib.pyplot as plt
8-
import numpy.random as rnd
8+
import numpy as np
99
from matplotlib.patches import Ellipse
1010

1111
NUM = 250
1212

13-
ells = [Ellipse(xy=rnd.rand(2)*10, width=rnd.rand(), height=rnd.rand(), angle=rnd.rand()*360)
13+
ells = [Ellipse(xy=np.random.rand(2)*10,
14+
width=np.random.rand(), height=np.random.rand(),
15+
angle=np.random.rand()*360)
1416
for i in range(NUM)]
1517

1618
fig, ax = plt.subplots(subplot_kw={'aspect': 'equal'})
1719
for e in ells:
1820
ax.add_artist(e)
1921
e.set_clip_box(ax.bbox)
20-
e.set_alpha(rnd.rand())
21-
e.set_facecolor(rnd.rand(3))
22+
e.set_alpha(np.random.rand())
23+
e.set_facecolor(np.random.rand(3))
2224

2325
ax.set_xlim(0, 10)
2426
ax.set_ylim(0, 10)

examples/pylab_examples/pcolor_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
"""
1111
import matplotlib.pyplot as plt
1212
import numpy as np
13-
from numpy.random import rand
1413
from matplotlib.colors import LogNorm
1514
from matplotlib.mlab import bivariate_normal
1615

16+
1717
###############################################################################
1818
# A simple pcolor demo
1919
# --------------------
2020

21-
Z = rand(6, 10)
21+
Z = np.random.rand(6, 10)
2222

2323
plt.subplot(2, 1, 1)
2424
c = plt.pcolor(Z)

examples/pylab_examples/spy_demos.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
"""
88

99
from matplotlib.pyplot import figure, show
10-
import numpy
10+
import numpy as np
1111

1212
fig = figure()
1313
ax1 = fig.add_subplot(221)
1414
ax2 = fig.add_subplot(222)
1515
ax3 = fig.add_subplot(223)
1616
ax4 = fig.add_subplot(224)
1717

18-
x = numpy.random.randn(20, 20)
18+
x = np.random.randn(20, 20)
1919
x[5] = 0.
2020
x[:, 12] = 0.
2121

examples/pylab_examples/subplot_toolbar.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
66
"""
77
import matplotlib.pyplot as plt
8-
import numpy.random as rnd
8+
import numpy as np
99

1010
fig = plt.figure()
1111
plt.subplot(221)
12-
plt.imshow(rnd.random((100, 100)))
12+
plt.imshow(np.random.random((100, 100)))
1313
plt.subplot(222)
14-
plt.imshow(rnd.random((100, 100)))
14+
plt.imshow(np.random.random((100, 100)))
1515
plt.subplot(223)
16-
plt.imshow(rnd.random((100, 100)))
16+
plt.imshow(np.random.random((100, 100)))
1717
plt.subplot(224)
18-
plt.imshow(rnd.random((100, 100)))
18+
plt.imshow(np.random.random((100, 100)))
1919

2020
plt.subplot_tool()
2121
plt.show()

examples/pylab_examples/tricontour_vs_griddata.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
import matplotlib.pyplot as plt
1010
import matplotlib.tri as tri
1111
import numpy as np
12-
import numpy.random as rnd
1312
import matplotlib.mlab as mlab
1413
import time
1514

16-
rnd.seed(0)
15+
np.random.seed(0)
1716
npts = 200
1817
ngridx = 100
1918
ngridy = 200
20-
x = rnd.uniform(-2, 2, npts)
21-
y = rnd.uniform(-2, 2, npts)
19+
x = np.random.uniform(-2, 2, npts)
20+
y = np.random.uniform(-2, 2, npts)
2221
z = x*np.exp(-x**2 - y**2)
2322

2423
# griddata and contour.

examples/pylab_examples/vline_hline_demo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import matplotlib.pyplot as plt
1010
from matplotlib.transforms import blended_transform_factory as btf
1111
import numpy as np
12-
import numpy.random as rnd
1312

1413

1514
def f(t):
@@ -19,7 +18,7 @@ def f(t):
1918

2019
t = np.arange(0.0, 5.0, 0.1)
2120
s = f(t)
22-
nse = rnd.normal(0.0, 0.3, t.shape) * s
21+
nse = np.random.normal(0.0, 0.3, t.shape) * s
2322

2423
fig = plt.figure(figsize=(12, 6))
2524
vax = fig.add_subplot(121)

examples/units/units_sample.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
"""
1616
from basic_units import cm, inch
1717
import matplotlib.pyplot as plt
18-
import numpy
18+
import numpy as np
1919

20-
cms = cm * numpy.arange(0, 10, 2)
20+
cms = cm * np.arange(0, 10, 2)
2121

2222
fig = plt.figure()
2323

examples/user_interfaces/histogram_demo_canvasagg_sgskip.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515
from matplotlib.backends.backend_agg import FigureCanvasAgg
1616
from matplotlib.figure import Figure
1717
from matplotlib.mlab import normpdf
18-
from numpy.random import randn
19-
import numpy
18+
import numpy as np
2019

2120
fig = Figure(figsize=(5, 4), dpi=100)
2221
ax = fig.add_subplot(111)
2322

2423
canvas = FigureCanvasAgg(fig)
2524

2625
mu, sigma = 100, 15
27-
x = mu + sigma*randn(10000)
26+
x = mu + sigma * np.random.randn(10000)
2827

2928
# the histogram of the data
3029
n, bins, patches = ax.hist(x, 50, normed=1)
@@ -52,7 +51,7 @@
5251

5352
if 0:
5453
# convert to a numpy array
55-
X = numpy.fromstring(s, numpy.uint8).reshape((h, w, 3))
54+
X = np.fromstring(s, np.uint8).reshape((h, w, 3))
5655

5756
if 0:
5857
# pass off to PIL

examples/userdemo/annotate_text_arrow.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
66
"""
77

8-
import numpy.random
8+
import numpy as np
99
import matplotlib.pyplot as plt
1010

1111
fig, ax = plt.subplots(figsize=(5, 5))
1212
ax.set_aspect(1)
1313

14-
x1 = -1 + numpy.random.randn(100)
15-
y1 = -1 + numpy.random.randn(100)
16-
x2 = 1. + numpy.random.randn(100)
17-
y2 = 1. + numpy.random.randn(100)
14+
x1 = -1 + np.random.randn(100)
15+
y1 = -1 + np.random.randn(100)
16+
x2 = 1. + np.random.randn(100)
17+
y2 = 1. + np.random.randn(100)
1818

1919
ax.scatter(x1, y1, color="r")
2020
ax.scatter(x2, y2, color="g")

0 commit comments

Comments
 (0)
0