I want to create a figure that consists of 7 plots, 5 boxplots and 2 histograms. The first four boxplots are in the first two rows, followed by a row for the two histograms, and in the last row the last boxplot (figure below). When I try to create this in matplotlib
, however, it creates a ton of vertical white space that is unnecessary (red rectangles in the provided images). I want to delete them, i.e. there should be as little as possible top and bottom white space in the plots. I have tried a few things, but nothing seems to work, subplot_adjust
(this seems to be the closest to what I want), margin
. The link to my python code so far is below, with additional two links on this topic. Thank you for your help!
import numpy as np
import matplotlib.pyplot as plt
dist = np.random.normal(0, 1, 1000)
FONT_SIZE = "xx-large"
fig = plt.figure(figsize=(16, 26))
fig.tight_layout()
gs = fig.add_gridspec(4, 2)
fig_ax1 = fig.add_subplot(gs[0, 0])
fig_ax1.boxplot(
dist,
notch=True,
vert=False)
fig_ax2 = fig.add_subplot(gs[0, 1])
fig_ax2.boxplot(
dist,
notch=True,
vert=False)
fig_ax3 = fig.add_subplot(gs[1, 0])
fig_ax3.boxplot(
dist,
notch=True,
vert=False)
fig_ax4 = fig.add_subplot(gs[1, 1])
fig_ax4.boxplot(
dist,
notch=True,
vert=False)
fig_ax5 = fig.add_subplot(gs[2, 0])
fig_ax5.hist(
dist,
bins=60)
fig_ax5.set_xlim(0, 0.02)
fig_ax6 = fig.add_subplot(gs[2, 1])
fig_ax6.hist(
dist,
bins=60)
fig_ax7 = fig.add_subplot(gs[3, :])
fig_ax7.boxplot(
dist,
notch=True,
vert=False)
Some links for that issue.
Zooming in and out using Axes.margins and the subject of "stickiness"