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

Skip to content

Commit f3f4bf0

Browse files
committed
MEP12 on image_masked.py
1 parent 024c96b commit f3f4bf0

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed
Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
#!/usr/bin/env python
2-
'''imshow with masked array input and out-of-range colors.
1+
"""
2+
imshow with masked array input and out-of-range colors.
33
4-
The second subplot illustrates the use of BoundaryNorm to
5-
get a filled contour effect.
6-
'''
4+
The second subplot illustrates the use of BoundaryNorm to
5+
get a filled contour effect.
6+
"""
77

8-
from pylab import *
98
from numpy import ma
109
import matplotlib.colors as colors
10+
import matplotlib.pyplot as plt
11+
import matplotlib.mlab as mlab
12+
import numpy as np
1113

1214
delta = 0.025
13-
x = y = arange(-3.0, 3.0, delta)
14-
X, Y = meshgrid(x, y)
15-
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
16-
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
15+
x = y = np.arange(-3.0, 3.0, delta)
16+
X, Y = np.meshgrid(x, y)
17+
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
18+
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
1719
Z = 10*(Z2 - Z1) # difference of Gaussians
1820

1921
# Set up a colormap:
20-
palette = cm.gray
22+
palette = plt.cm.gray
2123
palette.set_over('r', 1.0)
2224
palette.set_under('g', 1.0)
2325
palette.set_bad('b', 1.0)
@@ -33,22 +35,22 @@
3335
# range to which the regular palette color scale is applied.
3436
# Anything above that range is colored based on palette.set_over, etc.
3537

36-
subplot(1, 2, 1)
37-
im = imshow(Zm, interpolation='bilinear',
38-
cmap=palette,
39-
norm=colors.Normalize(vmin=-1.0, vmax=1.0, clip=False),
40-
origin='lower', extent=[-3, 3, -3, 3])
41-
title('Green=low, Red=high, Blue=bad')
42-
colorbar(im, extend='both', orientation='horizontal', shrink=0.8)
43-
44-
subplot(1, 2, 2)
45-
im = imshow(Zm, interpolation='nearest',
46-
cmap=palette,
47-
norm=colors.BoundaryNorm([-1, -0.5, -0.2, 0, 0.2, 0.5, 1],
48-
ncolors=256, clip=False),
49-
origin='lower', extent=[-3, 3, -3, 3])
50-
title('With BoundaryNorm')
51-
colorbar(im, extend='both', spacing='proportional',
52-
orientation='horizontal', shrink=0.8)
53-
54-
show()
38+
plt.subplot(1, 2, 1)
39+
im = plt.imshow(Zm, interpolation='bilinear',
40+
cmap=palette,
41+
norm=colors.Normalize(vmin=-1.0, vmax=1.0, clip=False),
42+
origin='lower', extent=[-3, 3, -3, 3])
43+
plt.title('Green=low, Red=high, Blue=bad')
44+
plt.colorbar(im, extend='both', orientation='horizontal', shrink=0.8)
45+
46+
plt.subplot(1, 2, 2)
47+
im = plt.imshow(Zm, interpolation='nearest',
48+
cmap=palette,
49+
norm=colors.BoundaryNorm([-1, -0.5, -0.2, 0, 0.2, 0.5, 1],
50+
ncolors=256, clip=False),
51+
origin='lower', extent=[-3, 3, -3, 3])
52+
plt.title('With BoundaryNorm')
53+
plt.colorbar(im, extend='both', spacing='proportional',
54+
orientation='horizontal', shrink=0.8)
55+
56+
plt.show()

0 commit comments

Comments
 (0)