|
33 | 33 | interior = np.sqrt(X**2 + Y**2) < 0.5 |
34 | 34 | Z[interior] = np.ma.masked |
35 | 35 |
|
36 | | -# We are using automatic selection of contour levels; |
37 | | -# this is usually not such a good idea, because they don't |
38 | | -# occur on nice boundaries, but we do it here for purposes |
39 | | -# of illustration. |
| 36 | +############################################################################# |
| 37 | +# Automatic contour levels |
| 38 | +# ------------------------ |
| 39 | +# We are using automatic selection of contour levels; this is usually not such |
| 40 | +# a good idea, because they don't occur on nice boundaries, but we do it here |
| 41 | +# for purposes of illustration. |
40 | 42 |
|
41 | 43 | fig1, ax2 = plt.subplots(constrained_layout=True) |
42 | 44 | CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.bone, origin=origin) |
|
58 | 60 | # Add the contour line levels to the colorbar |
59 | 61 | cbar.add_lines(CS2) |
60 | 62 |
|
| 63 | +############################################################################# |
| 64 | +# Explicit contour levels |
| 65 | +# ----------------------- |
| 66 | +# Now make a contour plot with the levels specified, and with the colormap |
| 67 | +# generated automatically from a list of colors. |
| 68 | + |
61 | 69 | fig2, ax2 = plt.subplots(constrained_layout=True) |
62 | | -# Now make a contour plot with the levels specified, |
63 | | -# and with the colormap generated automatically from a list |
64 | | -# of colors. |
65 | 70 | levels = [-1.5, -1, -0.5, 0, 0.5, 1] |
66 | 71 | CS3 = ax2.contourf(X, Y, Z, levels, |
67 | 72 | colors=('r', 'g', 'b'), |
|
84 | 89 | # needs from the ContourSet object, CS3. |
85 | 90 | fig2.colorbar(CS3) |
86 | 91 |
|
| 92 | +############################################################################# |
| 93 | +# Extension settings |
| 94 | +# ------------------ |
87 | 95 | # Illustrate all 4 possible "extend" settings: |
88 | 96 | extends = ["neither", "both", "min", "max"] |
89 | 97 | cmap = plt.colormaps["winter"].with_extremes(under="magenta", over="yellow") |
|
0 commit comments