Created
May 30, 2018 18:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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