【发布时间】:2016-08-10 11:09:43
【问题描述】:
我想在使用 Python 的 matplotlib 时更改 subplot 的大小。我已经知道如何更改 figure 的大小,但是,如何更改相应子图本身的大小?这在我的谷歌搜索中仍然有些难以捉摸。谢谢。
(例如,给定一个图,其中我们有 2x4 子图。我想让图中的子图占据更多区域)。
【问题讨论】:
标签: python numpy matplotlib plot figure
我想在使用 Python 的 matplotlib 时更改 subplot 的大小。我已经知道如何更改 figure 的大小,但是,如何更改相应子图本身的大小?这在我的谷歌搜索中仍然有些难以捉摸。谢谢。
(例如,给定一个图,其中我们有 2x4 子图。我想让图中的子图占据更多区域)。
【问题讨论】:
标签: python numpy matplotlib plot figure
您还可以使用轴大小。 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])
【讨论】:
您可以使用.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)
导致这个怪物:
【讨论】: