Skip to content

Instantly share code, notes, and snippets.

@donkirkby
Created May 30, 2018 18:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donkirkby/36e8c208926e2e85ca9dbd975fc9599f to your computer and use it in GitHub Desktop.
Save donkirkby/36e8c208926e2e85ca9dbd975fc9599f to your computer and use it in GitHub Desktop.
Matplotlib subplots example showing how to avoid overlap between suptitle and tight_layout
from math import ceil
from matplotlib import pyplot as plt
plot_count = 8
column_count = 2
row_count = int(ceil(plot_count/column_count))
fig, subplot_axes = plt.subplots(row_count,
column_count,
squeeze=False,
sharex='all',
sharey='all')
for i in range(plot_count):
row = i // column_count
col = i % column_count
ax = subplot_axes[row][col]
ax.set_title(i)
bits = []
for j in range(4):
bits.insert(0, i % 2)
i >>= 1
ax.plot(bits, drawstyle='steps-pre')
plt.suptitle('First few bit values in small numbers')
plt.tight_layout(rect=[0, 0, 1, 0.95])
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment