|
26 | 26 | levels = arange(-2.0, 1.601, 0.4) # Boost the upper limit to avoid truncation |
27 | 27 | # errors. |
28 | 28 |
|
| 29 | +norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max()) |
| 30 | +cmap = cm.PRGn |
| 31 | + |
29 | 32 | figure() |
30 | 33 |
|
31 | 34 |
|
32 | 35 | subplot(2,2,1) |
33 | 36 |
|
34 | 37 | cset1 = contourf(X, Y, Z, levels, |
35 | | - cmap=cm.get_cmap('jet', len(levels)-1), |
| 38 | + cmap=cm.get_cmap(cmap, len(levels)-1), |
| 39 | + norm=norm, |
36 | 40 | ) |
37 | 41 | # It is not necessary, but for the colormap, we need only the |
38 | 42 | # number of levels minus 1. To avoid discretization error, use |
|
65 | 69 |
|
66 | 70 | subplot(2,2,2) |
67 | 71 |
|
68 | | -imshow(Z, extent=extent) |
| 72 | +imshow(Z, extent=extent, cmap=cmap, norm=norm) |
69 | 73 | v = axis() |
70 | 74 | contour(Z, levels, hold='on', colors = 'k', |
71 | 75 | origin='upper', extent=extent) |
|
74 | 78 |
|
75 | 79 | subplot(2,2,3) |
76 | 80 |
|
77 | | -imshow(Z, origin='lower', extent=extent) |
| 81 | +imshow(Z, origin='lower', extent=extent, cmap=cmap, norm=norm) |
78 | 82 | v = axis() |
79 | 83 | contour(Z, levels, hold='on', colors = 'k', |
80 | 84 | origin='lower', extent=extent) |
|
89 | 93 | # This is intentional. The Z values are defined at the center of each |
90 | 94 | # image pixel (each color block on the following subplot), so the |
91 | 95 | # domain that is contoured does not extend beyond these pixel centers. |
92 | | -im = imshow(Z, interpolation='nearest', extent=extent) |
| 96 | +im = imshow(Z, interpolation='nearest', extent=extent, cmap=cmap, norm=norm) |
93 | 97 | v = axis() |
94 | 98 | contour(Z, levels, hold='on', colors = 'k', |
95 | 99 | origin='image', extent=extent) |
|
0 commit comments