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

2 Answers 2

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])
Sign up to request clarification or add additional context in comments.

3 Comments

May you please give an example illustrating this?
I added a quick example. Not tested though. I hope it can help you :)
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.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.