|
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. |
3 | 3 |
|
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 | +""" |
7 | 7 |
|
8 |
| -from pylab import * |
9 | 8 | from numpy import ma
|
10 | 9 | import matplotlib.colors as colors
|
| 10 | +import matplotlib.pyplot as plt |
| 11 | +import matplotlib.mlab as mlab |
| 12 | +import numpy as np |
11 | 13 |
|
12 | 14 | 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) |
17 | 19 | Z = 10*(Z2 - Z1) # difference of Gaussians
|
18 | 20 |
|
19 | 21 | # Set up a colormap:
|
20 |
| -palette = cm.gray |
| 22 | +palette = plt.cm.gray |
21 | 23 | palette.set_over('r', 1.0)
|
22 | 24 | palette.set_under('g', 1.0)
|
23 | 25 | palette.set_bad('b', 1.0)
|
|
33 | 35 | # range to which the regular palette color scale is applied.
|
34 | 36 | # Anything above that range is colored based on palette.set_over, etc.
|
35 | 37 |
|
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