在python matplotlib中更改子图大小

时间:2016-08-10 02:21:44

标签: python numpy matplotlib plot figure

当我使用Python的matplotlib时,我想更改子图的大小。我已经知道如何更改数字的大小,但是,如何更改相应子图本身的大小?这在我的谷歌搜索中仍然有点难以捉摸。谢谢。

(例如,给出一个我们有2x4子图的图。我想让图中的子图占据更多区域)。

2 个答案:

答案 0 :(得分:1)

您可以使用.subplots_adjust(),例如

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)

这种怪异的结果:

enter image description here

答案 1 :(得分:1)

您也可以使用轴尺寸。 http://matplotlib.org/api/axes_api.html

set_position()可用于更改轴的宽度和高度。

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])
相关问题