Skip to content

Commit ea26862

Browse files
committed
add colorbars, constrained layout
1 parent 920588d commit ea26862

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

examples/statistics/time_series_histogram.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import matplotlib.pyplot as plt
3232
from matplotlib.colors import LogNorm
3333

34-
fig, axes = plt.subplots(nrows=3, figsize=(6, 8))
34+
fig, axes = plt.subplots(nrows=3, figsize=(6, 8), constrained_layout=True)
3535

3636
# Make some data; a 1D random walk + small fraction of sine waves
3737
num_series = 1000
@@ -80,15 +80,17 @@
8080
cmap = copy(plt.cm.plasma)
8181
cmap.set_bad(cmap(0))
8282
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)
8586
axes[1].set_title("2d histogram and log color scale")
8687

8788
# 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)
8992
axes[2].set_title("2d histogram and linear color scale")
93+
9094
toc = time.time()
9195
print(f"{toc-tic:.3f} sec. elapsed")
92-
93-
fig.tight_layout()
9496
plt.show()

0 commit comments

Comments
 (0)