|
31 | 31 | import matplotlib.pyplot as plt
|
32 | 32 | from matplotlib.colors import LogNorm
|
33 | 33 |
|
34 |
| -fig, axes = plt.subplots(nrows=3, figsize=(6, 8)) |
| 34 | +fig, axes = plt.subplots(nrows=3, figsize=(6, 8), constrained_layout=True) |
35 | 35 |
|
36 | 36 | # Make some data; a 1D random walk + small fraction of sine waves
|
37 | 37 | num_series = 1000
|
|
80 | 80 | cmap = copy(plt.cm.plasma)
|
81 | 81 | cmap.set_bad(cmap(0))
|
82 | 82 | h, xedges, yedges = np.histogram2d(x_fine, y_fine, bins=[400, 100])
|
83 |
| -axes[1].pcolormesh(xedges, yedges, h.T, cmap=cmap, |
84 |
| - norm=LogNorm(vmax=1.5e2), rasterized=True) |
| 83 | +pcm = axes[1].pcolormesh(xedges, yedges, h.T, cmap=cmap, |
| 84 | + norm=LogNorm(vmax=1.5e2), rasterized=True) |
| 85 | +fig.colorbar(pcm, ax=axes[1], label="# points", pad=0) |
85 | 86 | axes[1].set_title("2d histogram and log color scale")
|
86 | 87 |
|
87 | 88 | # Same data but on linear color scale
|
88 |
| -axes[2].pcolormesh(xedges, yedges, h.T, cmap=cmap, vmax=1.5e2, rasterized=True) |
| 89 | +pcm = axes[2].pcolormesh(xedges, yedges, h.T, cmap=cmap, |
| 90 | + vmax=1.5e2, rasterized=True) |
| 91 | +fig.colorbar(pcm, ax=axes[2], label="# points", pad=0) |
89 | 92 | axes[2].set_title("2d histogram and linear color scale")
|
| 93 | + |
90 | 94 | toc = time.time()
|
91 | 95 | print(f"{toc-tic:.3f} sec. elapsed")
|
92 |
| - |
93 |
| -fig.tight_layout() |
94 | 96 | plt.show()
|
0 commit comments