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

Skip to content

Commit 72882be

Browse files
committed
Remove more mlab from examples
1 parent 22332ce commit 72882be

File tree

8 files changed

+39
-200
lines changed

8 files changed

+39
-200
lines changed

examples/images_contours_and_fields/griddata_demo.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

examples/images_contours_and_fields/tricontour_vs_griddata.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

examples/lines_bars_and_markers/interp_demo.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
66
"""
77
import matplotlib.pyplot as plt
8-
from numpy import pi, sin, linspace
9-
from matplotlib.mlab import stineman_interp
8+
import numpy as np
109

11-
x = linspace(0, 2*pi, 20)
12-
y = sin(x)
10+
x = np.linspace(0, 2 * np.pi, 20)
11+
y = np.sin(x)
1312
yp = None
14-
xi = linspace(x[0], x[-1], 100)
15-
yi = stineman_interp(xi, x, y, yp)
13+
xi = np.linspace(x[0], x[-1], 100)
14+
yi = np.interp(xi, x, y, yp)
1615

1716
fig, ax = plt.subplots()
1817
ax.plot(x, y, 'o', xi, yi, '.')

examples/misc/rec_groupby_demo.py

Lines changed: 0 additions & 71 deletions
This file was deleted.

examples/statistics/histogram_cumulative.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
66
This shows how to plot a cumulative, normalized histogram as a
77
step function in order to visualize the empirical cumulative
8-
distribution function (CDF) of a sample. We also use the ``mlab``
9-
module to show the theoretical CDF.
8+
distribution function (CDF) of a sample. We also show the theoretical CDF.
109
1110
A couple of other options to the ``hist`` function are demonstrated.
1211
Namely, we use the ``normed`` parameter to normalize the histogram and
@@ -37,7 +36,6 @@
3736

3837
import numpy as np
3938
import matplotlib.pyplot as plt
40-
from matplotlib import mlab
4139

4240
np.random.seed(19680801)
4341

@@ -53,7 +51,9 @@
5351
cumulative=True, label='Empirical')
5452

5553
# Add a line showing the expected distribution.
56-
y = mlab.normpdf(bins, mu, sigma).cumsum()
54+
y = ((1 / (np.sqrt(2 * np.pi) * sigma)) *
55+
np.exp(-0.5 * (1 / sigma * (bins - mu))**2))
56+
y = y.cumsum()
5757
y /= y[-1]
5858

5959
ax.plot(bins, y, 'k--', linewidth=1.5, label='Theoretical')

examples/statistics/histogram_features.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"""
2121

2222
import numpy as np
23-
import matplotlib.mlab as mlab
2423
import matplotlib.pyplot as plt
2524

2625
np.random.seed(19680801)
@@ -35,10 +34,11 @@
3534
fig, ax = plt.subplots()
3635

3736
# the histogram of the data
38-
n, bins, patches = ax.hist(x, num_bins, normed=1)
37+
n, bins, patches = ax.hist(x, num_bins, density=1)
3938

4039
# add a 'best fit' line
41-
y = mlab.normpdf(bins, mu, sigma)
40+
y = ((1 / (np.sqrt(2 * np.pi) * sigma)) *
41+
np.exp(-0.5 * (1 / sigma * (bins - mu))**2))
4242
ax.plot(bins, y, '--')
4343
ax.set_xlabel('Smarts')
4444
ax.set_ylabel('Probability density')

examples/user_interfaces/histogram_demo_canvasagg_sgskip.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"""
1515
from matplotlib.backends.backend_agg import FigureCanvasAgg
1616
from matplotlib.figure import Figure
17-
from matplotlib.mlab import normpdf
1817
import numpy as np
1918

2019
fig = Figure(figsize=(5, 4), dpi=100)
@@ -26,10 +25,11 @@
2625
x = mu + sigma * np.random.randn(10000)
2726

2827
# the histogram of the data
29-
n, bins, patches = ax.hist(x, 50, normed=1)
28+
n, bins, patches = ax.hist(x, 50, density=1)
3029

3130
# add a 'best fit' line
32-
y = normpdf(bins, mu, sigma)
31+
y = ((1 / (np.sqrt(2 * np.pi) * sigma)) *
32+
np.exp(-0.5 * (1 / sigma * (bins - mu))**2))
3333
line, = ax.plot(bins, y, 'r--')
3434
line.set_linewidth(1)
3535

tutorials/colors/colormapnorms.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,25 @@
4646
import numpy as np
4747
import matplotlib.pyplot as plt
4848
import matplotlib.colors as colors
49-
from matplotlib.mlab import bivariate_normal
5049

5150
N = 100
5251
X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)]
5352

5453
# A low hump with a spike coming out of the top right. Needs to have
5554
# z/colour axis on a log scale so we see both hump and spike. linear
5655
# scale only shows the spike.
57-
Z1 = bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0) + \
58-
0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
56+
Z1 = np.exp(-(X)**2 - (Y)**2)
57+
Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2)
58+
Z = Z1 + 50 * Z2
5959

6060
fig, ax = plt.subplots(2, 1)
6161

62-
pcm = ax[0].pcolor(X, Y, Z1,
63-
norm=colors.LogNorm(vmin=Z1.min(), vmax=Z1.max()),
62+
pcm = ax[0].pcolor(X, Y, Z,
63+
norm=colors.LogNorm(vmin=Z.min(), vmax=Z.max()),
6464
cmap='PuBu_r')
6565
fig.colorbar(pcm, ax=ax[0], extend='max')
6666

67-
pcm = ax[1].pcolor(X, Y, Z1, cmap='PuBu_r')
67+
pcm = ax[1].pcolor(X, Y, Z, cmap='PuBu_r')
6868
fig.colorbar(pcm, ax=ax[1], extend='max')
6969
fig.show()
7070

@@ -89,19 +89,19 @@
8989

9090
N = 100
9191
X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)]
92-
Z1 = (bivariate_normal(X, Y, 1., 1., 1.0, 1.0))**2 \
93-
- 0.4 * (bivariate_normal(X, Y, 1.0, 1.0, -1.0, 0.0))**2
94-
Z1 = Z1/0.03
92+
Z1 = np.exp(-X**2 - Y**2)
93+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
94+
Z = (Z1 - Z2) * 2
9595

9696
fig, ax = plt.subplots(2, 1)
9797

98-
pcm = ax[0].pcolormesh(X, Y, Z1,
98+
pcm = ax[0].pcolormesh(X, Y, Z,
9999
norm=colors.SymLogNorm(linthresh=0.03, linscale=0.03,
100100
vmin=-1.0, vmax=1.0),
101101
cmap='RdBu_r')
102102
fig.colorbar(pcm, ax=ax[0], extend='both')
103103

104-
pcm = ax[1].pcolormesh(X, Y, Z1, cmap='RdBu_r', vmin=-np.max(Z1))
104+
pcm = ax[1].pcolormesh(X, Y, Z, cmap='RdBu_r', vmin=-np.max(Z))
105105
fig.colorbar(pcm, ax=ax[1], extend='both')
106106
fig.show()
107107

@@ -129,7 +129,7 @@
129129

130130
fig, ax = plt.subplots(2, 1)
131131

132-
pcm = ax[0].pcolormesh(X, Y, Z1, norm=colors.PowerNorm(gamma=1./2.),
132+
pcm = ax[0].pcolormesh(X, Y, Z1, norm=colors.PowerNorm(gamma=0.5),
133133
cmap='PuBu_r')
134134
fig.colorbar(pcm, ax=ax[0], extend='max')
135135

@@ -162,27 +162,27 @@
162162

163163
N = 100
164164
X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)]
165-
Z1 = (bivariate_normal(X, Y, 1., 1., 1.0, 1.0))**2 \
166-
- 0.4 * (bivariate_normal(X, Y, 1.0, 1.0, -1.0, 0.0))**2
167-
Z1 = Z1/0.03
165+
Z1 = np.exp(-X**2 - Y**2)
166+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
167+
Z = (Z1 - Z2) * 2
168168

169169
fig, ax = plt.subplots(3, 1, figsize=(8, 8))
170170
ax = ax.flatten()
171171
# even bounds gives a contour-like effect
172172
bounds = np.linspace(-1, 1, 10)
173173
norm = colors.BoundaryNorm(boundaries=bounds, ncolors=256)
174-
pcm = ax[0].pcolormesh(X, Y, Z1,
174+
pcm = ax[0].pcolormesh(X, Y, Z,
175175
norm=norm,
176176
cmap='RdBu_r')
177177
fig.colorbar(pcm, ax=ax[0], extend='both', orientation='vertical')
178178

179179
# uneven bounds changes the colormapping:
180180
bounds = np.array([-0.25, -0.125, 0, 0.5, 1])
181181
norm = colors.BoundaryNorm(boundaries=bounds, ncolors=256)
182-
pcm = ax[1].pcolormesh(X, Y, Z1, norm=norm, cmap='RdBu_r')
182+
pcm = ax[1].pcolormesh(X, Y, Z, norm=norm, cmap='RdBu_r')
183183
fig.colorbar(pcm, ax=ax[1], extend='both', orientation='vertical')
184184

185-
pcm = ax[2].pcolormesh(X, Y, Z1, cmap='RdBu_r', vmin=-np.max(Z1))
185+
pcm = ax[2].pcolormesh(X, Y, Z, cmap='RdBu_r', vmin=-np.max(Z))
186186
fig.colorbar(pcm, ax=ax[2], extend='both', orientation='vertical')
187187
fig.show()
188188

@@ -207,9 +207,9 @@
207207

208208
N = 100
209209
X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)]
210-
Z1 = (bivariate_normal(X, Y, 1., 1., 1.0, 1.0))**2 \
211-
- 0.4 * (bivariate_normal(X, Y, 1.0, 1.0, -1.0, 0.0))**2
212-
Z1 = Z1/0.03
210+
Z1 = np.exp(-X**2 - Y**2)
211+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
212+
Z = (Z1 - Z2) * 2
213213

214214

215215
class MidpointNormalize(colors.Normalize):
@@ -223,13 +223,14 @@ def __call__(self, value, clip=None):
223223
x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1]
224224
return np.ma.masked_array(np.interp(value, x, y))
225225

226+
226227
fig, ax = plt.subplots(2, 1)
227228

228-
pcm = ax[0].pcolormesh(X, Y, Z1,
229+
pcm = ax[0].pcolormesh(X, Y, Z,
229230
norm=MidpointNormalize(midpoint=0.),
230231
cmap='RdBu_r')
231232
fig.colorbar(pcm, ax=ax[0], extend='both')
232233

233-
pcm = ax[1].pcolormesh(X, Y, Z1, cmap='RdBu_r', vmin=-np.max(Z1))
234+
pcm = ax[1].pcolormesh(X, Y, Z, cmap='RdBu_r', vmin=-np.max(Z))
234235
fig.colorbar(pcm, ax=ax[1], extend='both')
235236
fig.show()

0 commit comments

Comments
 (0)