1

I would like to change the size of the subplot when I use Python's matplotlib. I already know how to change the size of the figure, however, how does one go about changing the size of the corresponding subplots themselves? This has remained somewhat elusive in my googling. Thanks.

(For example, given a figure where we have 2x4 subplots. I want to make the subplots within the figure occupy more area).

TheGrapeBeyond
  • 543
  • 2
  • 8
  • 19

2 Answers2

4

You can also play with the axis size. http://matplotlib.org/api/axes_api.html

set_position() can be used to change width and height of your axis.

import matplotlib.pyplot as plt

ax = plt.subplot(111)

box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 1.1 , box.height * 1.1])
Shiriru
  • 181
  • 1
  • 10
  • May you please give an example illustrating this? – TheGrapeBeyond Aug 10 '16 at 02:53
  • I added a quick example. Not tested though. I hope it can help you :) – Shiriru Aug 10 '16 at 02:59
  • Thaks, I had been looking for something like this for long. However it has a strange behavior when I have one plot from imshow and the other from plt, and the figure is resized, as proportions are not maintained. – Vincenzooo Apr 03 '21 at 21:51
0

You can use .subplots_adjust(), e.g.

import seaborn as sns, matplotlib.pyplot as plt 

titanic = sns.load_dataset('titanic')

g = sns.factorplot(x='sex',y='age',hue='class',data=titanic,
                  kind='bar',ci=None,legend=False)
g.fig.suptitle('Oversized Plot',size=16)
plt.legend(loc='best')
g.fig.subplots_adjust(top=1.05,bottom=-0.05,left=-0.05,right=1.05)

Results in this monstrosity:

enter image description here

mechanical_meat
  • 163,903
  • 24
  • 228
  • 223