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

Skip to content

Commit 80008a2

Browse files
committed
more complicated example of centered norm diverging colormap
1 parent f3ba478 commit 80008a2

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

examples/pylab_examples/contour_image.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@
2626
levels = arange(-2.0, 1.601, 0.4) # Boost the upper limit to avoid truncation
2727
# errors.
2828

29+
norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())
30+
cmap = cm.PRGn
31+
2932
figure()
3033

3134

3235
subplot(2,2,1)
3336

3437
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,
3640
)
3741
# It is not necessary, but for the colormap, we need only the
3842
# number of levels minus 1. To avoid discretization error, use
@@ -65,7 +69,7 @@
6569

6670
subplot(2,2,2)
6771

68-
imshow(Z, extent=extent)
72+
imshow(Z, extent=extent, cmap=cmap, norm=norm)
6973
v = axis()
7074
contour(Z, levels, hold='on', colors = 'k',
7175
origin='upper', extent=extent)
@@ -74,7 +78,7 @@
7478

7579
subplot(2,2,3)
7680

77-
imshow(Z, origin='lower', extent=extent)
81+
imshow(Z, origin='lower', extent=extent, cmap=cmap, norm=norm)
7882
v = axis()
7983
contour(Z, levels, hold='on', colors = 'k',
8084
origin='lower', extent=extent)
@@ -89,7 +93,7 @@
8993
# This is intentional. The Z values are defined at the center of each
9094
# image pixel (each color block on the following subplot), so the
9195
# 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)
9397
v = axis()
9498
contour(Z, levels, hold='on', colors = 'k',
9599
origin='image', extent=extent)

0 commit comments

Comments
 (0)