|
20 | 20 |
|
21 | 21 | Z = np.random.rand(6, 10) |
22 | 22 |
|
23 | | -plt.subplot(2, 1, 1) |
24 | | -c = plt.pcolor(Z) |
25 | | -plt.title('default: no edges') |
| 23 | +fig, (ax0, ax1) = plt.subplots(2, 1) |
26 | 24 |
|
27 | | -plt.subplot(2, 1, 2) |
28 | | -c = plt.pcolor(Z, edgecolors='k', linewidths=4) |
29 | | -plt.title('thick edges') |
| 25 | +c = ax0.pcolor(Z) |
| 26 | +ax0.set_title('default: no edges') |
| 27 | + |
| 28 | +c = ax1.pcolor(Z, edgecolors='k', linewidths=4) |
| 29 | +ax1.set_title('thick edges') |
30 | 30 |
|
31 | 31 | plt.show() |
32 | 32 |
|
|
49 | 49 | z = z[:-1, :-1] |
50 | 50 | z_min, z_max = -np.abs(z).max(), np.abs(z).max() |
51 | 51 |
|
| 52 | +fig, axs = plt.subplots(2, 2) |
52 | 53 |
|
53 | | -plt.subplot(2, 2, 1) |
54 | | -plt.pcolor(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max) |
55 | | -plt.title('pcolor') |
| 54 | +ax = axs[0, 0] |
| 55 | +c = ax.pcolor(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max) |
| 56 | +ax.set_title('pcolor') |
56 | 57 | # set the limits of the plot to the limits of the data |
57 | | -plt.axis([x.min(), x.max(), y.min(), y.max()]) |
58 | | -plt.colorbar() |
59 | | - |
| 58 | +ax.axis([x.min(), x.max(), y.min(), y.max()]) |
| 59 | +fig.colorbar(c, ax=ax) |
60 | 60 |
|
61 | | -plt.subplot(2, 2, 2) |
62 | | -plt.pcolormesh(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max) |
63 | | -plt.title('pcolormesh') |
| 61 | +ax = axs[0, 1] |
| 62 | +c = ax.pcolormesh(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max) |
| 63 | +ax.set_title('pcolormesh') |
64 | 64 | # set the limits of the plot to the limits of the data |
65 | | -plt.axis([x.min(), x.max(), y.min(), y.max()]) |
66 | | -plt.colorbar() |
67 | | - |
| 65 | +ax.axis([x.min(), x.max(), y.min(), y.max()]) |
| 66 | +fig.colorbar(c, ax=ax) |
68 | 67 |
|
69 | | -plt.subplot(2, 2, 3) |
70 | | -plt.imshow(z, cmap='RdBu', vmin=z_min, vmax=z_max, |
71 | | - extent=[x.min(), x.max(), y.min(), y.max()], |
72 | | - interpolation='nearest', origin='lower') |
73 | | -plt.title('image (nearest)') |
74 | | -plt.colorbar() |
| 68 | +ax = axs[1, 0] |
| 69 | +c = ax.imshow(z, cmap='RdBu', vmin=z_min, vmax=z_max, |
| 70 | + extent=[x.min(), x.max(), y.min(), y.max()], |
| 71 | + interpolation='nearest', origin='lower') |
| 72 | +ax.set_title('image (nearest)') |
| 73 | +fig.colorbar(c, ax=ax) |
75 | 74 |
|
| 75 | +ax = axs[1, 1] |
| 76 | +c = ax.pcolorfast(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max) |
| 77 | +ax.set_title('pcolorfast') |
| 78 | +fig.colorbar(c, ax=ax) |
76 | 79 |
|
77 | | -ax = plt.subplot(2, 2, 4) |
78 | | -ax.pcolorfast(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max) |
79 | | -plt.title('pcolorfast') |
80 | | -plt.colorbar() |
81 | | - |
82 | | -plt.subplots_adjust(wspace=0.5, hspace=0.5) |
| 80 | +fig.subplots_adjust(wspace=0.5, hspace=0.5) |
83 | 81 |
|
84 | 82 | plt.show() |
85 | 83 |
|
|
98 | 96 | # linear scale only shows the spike. |
99 | 97 | Z1 = bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0) + 0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) |
100 | 98 |
|
101 | | -plt.subplot(2, 1, 1) |
102 | | -plt.pcolor(X, Y, Z1, norm=LogNorm(vmin=Z1.min(), vmax=Z1.max()), cmap='PuBu_r') |
103 | | -plt.colorbar() |
| 99 | +fig, (ax0, ax1) = plt.subplots(2, 1) |
| 100 | + |
| 101 | +c = ax0.pcolor(X, Y, Z1, |
| 102 | + norm=LogNorm(vmin=Z1.min(), vmax=Z1.max()), cmap='PuBu_r') |
| 103 | +fig.colorbar(c, ax=ax0) |
104 | 104 |
|
105 | | -plt.subplot(2, 1, 2) |
106 | | -plt.pcolor(X, Y, Z1, cmap='PuBu_r') |
107 | | -plt.colorbar() |
| 105 | +c = ax1.pcolor(X, Y, Z1, cmap='PuBu_r') |
| 106 | +fig.colorbar(c, ax=ax1) |
108 | 107 |
|
109 | 108 | plt.show() |
0 commit comments