【问题标题】:How to adjust size of Seaborn distribution graph如何调整 Seaborn 分布图的大小
【发布时间】:2020-06-18 19:53:19
【问题描述】:
我想在Seaborn 中调整此分布图的大小。我从在线教程和文档中尝试了几种方法,但似乎没有任何效果。我觉得这真的很令人困惑,因为它看起来不同的情节,如plt,sns 有不同的功能,似乎不能互换工作......
我的代码:
import seaborn as sns
g = sns.distplot(df['data'])
g.fig.set_figwidth(20)
g.fig.set_figheight(10)
【问题讨论】:
标签:
python
matplotlib
plot
seaborn
google-colaboratory
【解决方案1】:
g 是matplotlib.axes._subplots.AxesSubplot(尝试type(g) 来查看)。如果您执行dir(g),您会看到它没有fig 方法/属性。但它有一个figure 属性。所以改变你的代码来反映这一点,你就会得到你需要的东西。
import seaborn as sns
g = sns.distplot(df['data'])
g.figure.set_figwidth(20)
g.figure.set_figheight(10)
【解决方案2】:
感谢@Sinan Kurmus 的回答,只是另一种解决方案:
plt.figure(figsize=(30,10)) # Use this line
# plt.gcf().subplots_adjust(left = 0.3)
g = sns.distplot(df['data'])