I thought switching from ax.set_xlim
to ax.set_xbound
was gonna solve my problem but I'm still unable to get rid of the white space in my subplots. Even more curiously, ax.set_ybound
, when added, behaves as expected, but ax.set_xbound
seems to have no effect on my plot.
Below is my code and resulting plot image for plotting 9 random images.
# Generate fake data for plotting
def random_img():
return np.random.randint(0, 255, (28,28))
images_to_plot = [random_img() for x in range(9)]
# Prep plotting figure space
plt.clf()
fig, axes = plt.subplots(3,3, sharex=True, sharey=True)
plt.style.use('seaborn-muted')
# Plot on subplot axes
for i in range(9):
# axes (subplot) objects are stored in 2d array, accessed with axes[row,col]
subplot_row = i//3
subplot_col = i%3
ax = axes[subplot_row, subplot_col]
# Plot image on subplot
ax.imshow(images_to_plot[i], cmap='gray')
# WHY DOESNT THIS RESTRICT THE BOUNDS OF THE X-AXIS???
ax.set_xbound([0,28])
plt.tight_layout()
plt.show()