|
8 | 8 | import matplotlib.pyplot as plt |
9 | 9 | import numpy as np |
10 | 10 |
|
11 | | -origin = 'lower' |
12 | | - |
13 | 11 | delta = 0.025 |
14 | 12 |
|
15 | 13 | x = y = np.arange(-3.0, 3.01, delta) |
|
41 | 39 | # for purposes of illustration. |
42 | 40 |
|
43 | 41 | fig1, ax2 = plt.subplots(layout='constrained') |
44 | | -CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.bone, origin=origin) |
| 42 | +CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.bone) |
45 | 43 |
|
46 | 44 | # Note that in the following, we explicitly pass in a subset of the contour |
47 | 45 | # levels used for the filled contours. Alternatively, we could pass in |
48 | 46 | # additional levels to provide extra resolution, or leave out the *levels* |
49 | 47 | # keyword argument to use all of the original levels. |
50 | 48 |
|
51 | | -CS2 = ax2.contour(CS, levels=CS.levels[::2], colors='r', origin=origin) |
| 49 | +CS2 = ax2.contour(CS, levels=CS.levels[::2], colors='r') |
52 | 50 |
|
53 | 51 | ax2.set_title('Nonsense (3 masked regions)') |
54 | 52 | ax2.set_xlabel('word length anomaly') |
|
68 | 66 |
|
69 | 67 | fig2, ax2 = plt.subplots(layout='constrained') |
70 | 68 | levels = [-1.5, -1, -0.5, 0, 0.5, 1] |
71 | | -CS3 = ax2.contourf(X, Y, Z, levels, |
72 | | - colors=('r', 'g', 'b'), |
73 | | - origin=origin, |
74 | | - extend='both') |
| 69 | +CS3 = ax2.contourf(X, Y, Z, levels, colors=('r', 'g', 'b'), extend='both') |
75 | 70 | # Our data range extends outside the range of levels; make |
76 | 71 | # data below the lowest contour level yellow, and above the |
77 | 72 | # highest level cyan: |
78 | 73 | CS3.cmap.set_under('yellow') |
79 | 74 | CS3.cmap.set_over('cyan') |
80 | 75 |
|
81 | | -CS4 = ax2.contour(X, Y, Z, levels, |
82 | | - colors=('k',), |
83 | | - linewidths=(3,), |
84 | | - origin=origin) |
| 76 | +CS4 = ax2.contour(X, Y, Z, levels, colors=('k',), linewidths=(3,)) |
85 | 77 | ax2.set_title('Listed colors (3 masked regions)') |
86 | 78 | ax2.clabel(CS4, fmt='%2.1f', colors='w', fontsize=14) |
87 | 79 |
|
|
104 | 96 | fig, axs = plt.subplots(2, 2, layout="constrained") |
105 | 97 |
|
106 | 98 | for ax, extend in zip(axs.flat, extends): |
107 | | - cs = ax.contourf(X, Y, Z, levels, cmap=cmap, extend=extend, origin=origin) |
| 99 | + cs = ax.contourf(X, Y, Z, levels, cmap=cmap, extend=extend) |
108 | 100 | fig.colorbar(cs, ax=ax, shrink=0.9) |
109 | 101 | ax.set_title("extend = %s" % extend) |
110 | 102 | ax.locator_params(nbins=4) |
111 | 103 |
|
112 | 104 | plt.show() |
113 | 105 |
|
| 106 | +# %% |
| 107 | +# Orient contour plots using the origin keyword |
| 108 | +# --------------------------------------------- |
| 109 | +# This code demonstrates orienting contour plot data using the "origin" keyword |
| 110 | + |
| 111 | +x = np.arange(1, 10) |
| 112 | +y = x.reshape(-1, 1) |
| 113 | +h = x * y |
| 114 | + |
| 115 | +fig, (ax1, ax2) = plt.subplots(ncols=2) |
| 116 | + |
| 117 | +ax1.set_title("origin='upper'") |
| 118 | +ax2.set_title("origin='lower'") |
| 119 | +ax1.contourf(h, levels=np.arange(5, 70, 5), extend='both', origin="upper") |
| 120 | +ax2.contourf(h, levels=np.arange(5, 70, 5), extend='both', origin="lower") |
| 121 | + |
| 122 | +plt.show() |
| 123 | + |
114 | 124 | # %% |
115 | 125 | # |
116 | 126 | # .. admonition:: References |
|
0 commit comments