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

Skip to content

Commit 3e37306

Browse files
authored
Merge pull request #9151 from dstansby/mlab-deprecate
API: Deprecate mlab functions
2 parents 0f42e10 + 4c61a1d commit 3e37306

39 files changed

+356
-482
lines changed

examples/api/affine_image.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"""
1010

1111
import numpy as np
12-
import matplotlib.mlab as mlab
1312
import matplotlib.pyplot as plt
1413
import matplotlib.transforms as mtransforms
1514

@@ -18,9 +17,9 @@ def get_image():
1817
delta = 0.25
1918
x = y = np.arange(-3.0, 3.0, delta)
2019
X, Y = np.meshgrid(x, y)
21-
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
22-
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
23-
Z = Z2 - Z1 # difference of Gaussians
20+
Z1 = np.exp(-X**2 - Y**2)
21+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
22+
Z = (Z1 - Z2)
2423
return Z
2524

2625

examples/frontpage/contour.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@
88

99
import matplotlib.pyplot as plt
1010
import numpy as np
11-
from matplotlib import mlab, cm
11+
from matplotlib import cm
1212

1313
extent = (-3, 3, -3, 3)
1414

1515
delta = 0.5
1616
x = np.arange(-3.0, 4.001, delta)
1717
y = np.arange(-4.0, 3.001, delta)
1818
X, Y = np.meshgrid(x, y)
19-
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, -0.5)
20-
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
21-
Z = (Z1 - Z2) * 10
19+
Z1 = np.exp(-X**2 - Y**2)
20+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
21+
Z = Z1 - Z2
2222

23-
levels = np.linspace(-2.0, 1.601, 40)
2423
norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())
2524

2625
fig, ax = plt.subplots()
2726
cset1 = ax.contourf(
28-
X, Y, Z, levels,
27+
X, Y, Z, 40,
2928
norm=norm)
30-
ax.set_xlim(-3, 3)
31-
ax.set_ylim(-3, 3)
29+
ax.set_xlim(-2, 2)
30+
ax.set_ylim(-2, 2)
3231
ax.set_xticks([])
3332
ax.set_yticks([])
3433
fig.savefig("contour_frontpage.png", dpi=25) # results in 160x120 px image
34+
plt.show()

examples/images_contours_and_fields/contour_demo.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import matplotlib
1212
import numpy as np
1313
import matplotlib.cm as cm
14-
import matplotlib.mlab as mlab
1514
import matplotlib.pyplot as plt
1615

1716
matplotlib.rcParams['xtick.direction'] = 'out'
@@ -21,10 +20,9 @@
2120
x = np.arange(-3.0, 3.0, delta)
2221
y = np.arange(-2.0, 2.0, delta)
2322
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)
26-
# difference of Gaussians
27-
Z = 10.0 * (Z2 - Z1)
23+
Z1 = np.exp(-X**2 - Y**2)
24+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
25+
Z = (Z1 - Z2) * 2
2826

2927
###############################################################################
3028
# Create a simple contour plot with labels using default colors. The

examples/images_contours_and_fields/contour_image.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"""
1414
import matplotlib.pyplot as plt
1515
import numpy as np
16-
from matplotlib import mlab, cm
16+
from matplotlib import cm
1717

1818
# Default delta is large because that makes it fast, and it illustrates
1919
# the correct registration between image and contours.
@@ -24,9 +24,9 @@
2424
x = np.arange(-3.0, 4.001, delta)
2525
y = np.arange(-4.0, 3.001, delta)
2626
X, Y = np.meshgrid(x, y)
27-
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
28-
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
29-
Z = (Z1 - Z2) * 10
27+
Z1 = np.exp(-X**2 - Y**2)
28+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
29+
Z = (Z1 - Z2) * 2
3030

3131
# Boost the upper limit to avoid truncation errors.
3232
levels = np.arange(-2.0, 1.601, 0.4)

examples/images_contours_and_fields/contour_label_demo.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import matplotlib
1212
import numpy as np
1313
import matplotlib.cm as cm
14-
import matplotlib.mlab as mlab
1514
import matplotlib.ticker as ticker
1615
import matplotlib.pyplot as plt
1716

@@ -25,10 +24,9 @@
2524
x = np.arange(-3.0, 3.0, delta)
2625
y = np.arange(-2.0, 2.0, delta)
2726
X, Y = np.meshgrid(x, y)
28-
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
29-
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
30-
# difference of Gaussians
31-
Z = 10.0 * (Z2 - Z1)
27+
Z1 = np.exp(-X**2 - Y**2)
28+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
29+
Z = (Z1 - Z2) * 2
3230

3331
###############################################################################
3432
# Make contour labels using creative float classes

examples/images_contours_and_fields/contourf_demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
x = y = np.arange(-3.0, 3.01, delta)
1616
X, Y = np.meshgrid(x, y)
17-
Z1 = plt.mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
18-
Z2 = plt.mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
19-
Z = 10 * (Z1 - Z2)
17+
Z1 = np.exp(-X**2 - Y**2)
18+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
19+
Z = (Z1 - Z2) * 2
2020

2121
nr, nc = Z.shape
2222

examples/images_contours_and_fields/contourf_log.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
import numpy as np
1111
from numpy import ma
1212
from matplotlib import ticker, cm
13-
from matplotlib.mlab import bivariate_normal
1413

1514
N = 100
1615
x = np.linspace(-3.0, 3.0, N)
1716
y = np.linspace(-2.0, 2.0, N)
1817

1918
X, Y = np.meshgrid(x, y)
2019

21-
# A low hump with a spike coming out of the top right.
20+
# A low hump with a spike coming out.
2221
# Needs to have z/colour axis on a log scale so we see both hump and spike.
2322
# linear scale only shows the spike.
24-
z = (bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0)
25-
+ 0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0))
23+
Z1 = np.exp(-(X)**2 - (Y)**2)
24+
Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2)
25+
z = Z1 + 50 * Z2
2626

2727
# Put in some negative values (lower left corner) to cause trouble with logs:
2828
z[:5, :5] = -1
@@ -39,10 +39,10 @@
3939

4040
# Alternatively, you can manually set the levels
4141
# and the norm:
42-
#lev_exp = np.arange(np.floor(np.log10(z.min())-1),
42+
# lev_exp = np.arange(np.floor(np.log10(z.min())-1),
4343
# np.ceil(np.log10(z.max())+1))
44-
#levs = np.power(10, lev_exp)
45-
#cs = P.contourf(X, Y, z, levs, norm=colors.LogNorm())
44+
# levs = np.power(10, lev_exp)
45+
# cs = P.contourf(X, Y, z, levs, norm=colors.LogNorm())
4646

4747
# The 'extend' kwarg does not work yet with a log scale.
4848

examples/images_contours_and_fields/griddata_demo.py

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

examples/images_contours_and_fields/image_demo.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import numpy as np
1616
import matplotlib.cm as cm
17-
import matplotlib.mlab as mlab
1817
import matplotlib.pyplot as plt
1918
import matplotlib.cbook as cbook
2019
from matplotlib.path import Path
@@ -26,9 +25,9 @@
2625
delta = 0.025
2726
x = y = np.arange(-3.0, 3.0, delta)
2827
X, Y = np.meshgrid(x, y)
29-
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
30-
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
31-
Z = Z2 - Z1 # difference of Gaussians
28+
Z1 = np.exp(-X**2 - Y**2)
29+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
30+
Z = (Z1 - Z2) * 2
3231

3332
im = plt.imshow(Z, interpolation='bilinear', cmap=cm.RdYlGn,
3433
origin='lower', extent=[-3, 3, -3, 3],
@@ -156,9 +155,9 @@
156155
delta = 0.025
157156
x = y = np.arange(-3.0, 3.0, delta)
158157
X, Y = np.meshgrid(x, y)
159-
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
160-
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
161-
Z = Z2 - Z1 # difference of Gaussians
158+
Z1 = np.exp(-X**2 - Y**2)
159+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
160+
Z = (Z1 - Z2) * 2
162161

163162
path = Path([[0, 1], [1, 0], [0, -1], [-1, 0], [0, 1]])
164163
patch = PathPatch(path, facecolor='none')

examples/images_contours_and_fields/image_masked.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313
import numpy as np
1414
import matplotlib.pyplot as plt
1515
import matplotlib.colors as colors
16-
import matplotlib.mlab as mlab
1716

1817
# compute some interesting data
1918
x0, x1 = -5, 5
2019
y0, y1 = -3, 3
2120
x = np.linspace(x0, x1, 500)
2221
y = np.linspace(y0, y1, 500)
2322
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)
26-
Z = 10*(Z2 - Z1) # difference of Gaussians
23+
Z1 = np.exp(-X**2 - Y**2)
24+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
25+
Z = (Z1 - Z2) * 2
2726

2827
# Set up a colormap:
2928
# use copy so that we do not mutate the global colormap instance

examples/images_contours_and_fields/pcolor_demo.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import matplotlib.pyplot as plt
1212
import numpy as np
1313
from matplotlib.colors import LogNorm
14-
from matplotlib.mlab import bivariate_normal
15-
1614

1715
###############################################################################
1816
# A simple pcolor demo
@@ -91,19 +89,20 @@
9189
N = 100
9290
X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)]
9391

94-
# A low hump with a spike coming out of the top right.
92+
# A low hump with a spike coming out.
9593
# Needs to have z/colour axis on a log scale so we see both hump and spike.
9694
# linear scale only shows the spike.
97-
Z1 = (bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0) +
98-
0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0))
95+
Z1 = np.exp(-(X)**2 - (Y)**2)
96+
Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2)
97+
Z = Z1 + 50 * Z2
9998

10099
fig, (ax0, ax1) = plt.subplots(2, 1)
101100

102-
c = ax0.pcolor(X, Y, Z1,
103-
norm=LogNorm(vmin=Z1.min(), vmax=Z1.max()), cmap='PuBu_r')
101+
c = ax0.pcolor(X, Y, Z,
102+
norm=LogNorm(vmin=Z.min(), vmax=Z.max()), cmap='PuBu_r')
104103
fig.colorbar(c, ax=ax0)
105104

106-
c = ax1.pcolor(X, Y, Z1, cmap='PuBu_r')
105+
c = ax1.pcolor(X, Y, Z, cmap='PuBu_r')
107106
fig.colorbar(c, ax=ax1)
108107

109108
plt.show()

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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
"""
77
import matplotlib.pyplot as plt
88
import numpy as np
9-
from matplotlib.mlab import stineman_interp
109

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

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

examples/misc/demo_agg_filter.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import numpy as np
1010
import matplotlib.cm as cm
11-
import matplotlib.mlab as mlab
1211
import matplotlib.transforms as mtransforms
1312
from matplotlib.colors import LightSource
1413
from matplotlib.artist import Artist
@@ -187,10 +186,9 @@ def filtered_text(ax):
187186
x = np.arange(-3.0, 3.0, delta)
188187
y = np.arange(-2.0, 2.0, delta)
189188
X, Y = np.meshgrid(x, y)
190-
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
191-
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
192-
# difference of Gaussians
193-
Z = 10.0 * (Z2 - Z1)
189+
Z1 = np.exp(-X**2 - Y**2)
190+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
191+
Z = (Z1 - Z2) * 2
194192

195193
# draw
196194
im = ax.imshow(Z, interpolation='bilinear', origin='lower',

0 commit comments

Comments
 (0)