I am using the following code to make plots:
fig, axes = plt.subplots(len(pairs), 3, figsize=(12, 324))
for i, pair in enumerate(pairs):
d = pd.DataFrame(columns=[pairs[0], pairs[1]])
e = df_norm[list(pair)]
ax0 = axes[i,0]
ax1 = axes[i,1]
ax2 = axes[i,2]
d[pair[0]] = np.random.normal(e[pair[0]],0.02)
d[pair[1]] = np.random.normal(e[pair[1]],0.02)
d.plot.scatter(*pair, ax=ax0, c=col0, linewidths=0, s=2, alpha = 0.7)
d.plot.scatter(*pair, ax=ax1, c=col1, linewidths=0, s=2, alpha = 0.7)
d.plot.scatter(*pair, ax=ax2, c=col2, linewidths=0, s=2, alpha = 0.7)
fig.tight_layout()
However, my output plot all messed up like:
I try to change figsize=(12, 324)
by making 324 bigger or smaller, but neither helps. Is there a way I can put some spaces between each row so the figures won't mess up. Thanks!
We can use the plt. subplots_adjust() method to change the space between Matplotlib subplots. The parameters wspace and hspace specify the space reserved between Matplotlib subplots.
To remove the space between subplots in matplotlib, we can use GridSpec(3, 3) class and add axes as a subplot arrangement.
You can use plt. subplots_adjust to change the spacing between the subplots.
For subplots, this can be done manually by adjusting the subplot parameters using Figure. subplots_adjust . Figure. tight_layout does this automatically.
You need to ommit fig.tight_layout()
and instead use subplots_adjust
.
plt.subplots_adjust(top = 0.99, bottom=0.01, hspace=1.5, wspace=0.4)
with some very extreme values. hspace
is the vertical gap between subplots (most probably in units of the subplot-height).
Figure
has the same subplots_adjust
method, so you can decide which one to chose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With