TheGrapeBeyond
TheGrapeBeyond

Reputation: 563

Change subplot size in python matplotlib

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).

Upvotes: 1

Views: 7899

Answers (2)

mechanical_meat
mechanical_meat

Reputation: 169494

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

Upvotes: 0

Shiriru
Shiriru

Reputation: 311

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])

Upvotes: 4

Related Questions