|
1 |
| -# Combination of quadmesh_demo and test_axes.test_pcolormesh. |
| 1 | +# Modified from quadmesh_demo and test_axes.test_pcolormesh. |
2 | 2 |
|
3 | 3 | from matplotlib import pyplot as plt
|
| 4 | +from matplotlib.colors import ListedColormap |
4 | 5 | import numpy as np
|
5 | 6 |
|
6 | 7 | n = 12
|
|
16 | 17 | # The color array can include masked values:
|
17 | 18 | Zm = np.ma.masked_where(np.abs(Qz) < 0.5 * np.max(Qz), Z)
|
18 | 19 |
|
19 |
| -fig, axs = plt.subplots(2, 2) |
20 |
| -axs[0, 0].pcolormesh(Qx, Qz, Z, shading='gouraud') |
21 |
| -axs[0, 1].pcolormesh(Qx, Qz, Zm, shading='gouraud') |
22 |
| -axs[1, 0].pcolormesh(Qx, Qz, Z, lw=0.5, edgecolors='k') |
23 |
| -axs[1, 1].pcolormesh(Qx, Qz, Z, lw=2, edgecolors=['b', 'w']) |
| 20 | +# Set up the colormaps |
| 21 | +cmap = plt.get_cmap('viridis') |
| 22 | +cmap_data = cmap(np.arange(cmap.N)) |
| 23 | +# Set a linear ramp in alpha |
| 24 | +cmap_data[:,-1] = np.linspace(0.2, 0.8, cmap.N) |
| 25 | +# Create new colormap |
| 26 | +cmap_alpha = ListedColormap(cmap_data) |
| 27 | + |
| 28 | +fig, axs = plt.subplots(2, 2, constrained_layout=True) |
| 29 | +axs[0, 0].pcolormesh(Qx, Qz, Z, cmap=cmap_alpha, shading='gouraud') |
| 30 | +axs[0, 1].pcolormesh(Qx, Qz, Zm, cmap=cmap_alpha, shading='gouraud') |
| 31 | +axs[1, 0].pcolormesh(Qx, Qz, Z, cmap=cmap_alpha, edgecolors='k') |
| 32 | +mesh = axs[1, 1].pcolormesh(Qx, Qz, Zm, cmap=cmap_alpha) |
| 33 | +fig.colorbar(mesh, ax=axs[:, 1], orientation='vertical') |
| 34 | + |
24 | 35 | for ax in axs.flat:
|
25 | 36 | ax.set_axis_off()
|
26 |
| -fig.tight_layout() |
27 | 37 |
|
28 | 38 | plt.show()
|
0 commit comments