pretzlstyle
pretzlstyle

Reputation: 2962

Why are my pyplot subplots only taking up half of the figure?

I am creating two subplots, side by side, and for some reason they will only fill the top half of the figure.

grid = {'width_ratios':[3,1],'height_ratios':[1,1]}
self.fig, self.axes = plt.subplots(1,2, sharey=True, gridspec_kw=grid)

And here is what it looks like once I plot everything:

probs

See how the bottom half of the image is blank? That is how it appears in the figure window. I want the entire figure of subplots to fill the window and be more square shaped, and I can't see any reason why it shouldn't, as I have written it.

Upvotes: 0

Views: 883

Answers (1)

Bart
Bart

Reputation: 10258

By declaring 'height_ratios':[1,1] you are creating two rows of subplots; similarly 'height_ratios':[1,1,1] will give you three rows, et cetera. So simply write 'height_ratios':[1], or leave out height_ratios, and it is fixed.

It's seems strange to me that this setting overrides the explicit nrows, ncols settings in Gridspec, but apparently that is what Matplotlib does.... Well, it doesn't override the nrows, ncols setting, but with 'height_ratios':[1,1] you are still creating space for two rows of subplots.

Upvotes: 1

Related Questions