python - plt.figure 不调整图形大小
问题描述
我有这个功能,我想改变图形的大小,但是无论我在 figsize 中输入什么值,图形大小都不会改变。任何人都可以提出什么问题吗?或者是否有其他方法可以做到这一点?
def plot_comparison_barplots(df, bar_col, hue_col, scaled):
fig = plt.figure(figsize=(12,10))
fig.set_tight_layout(True)
plt.rcParams.update({'font.size': 9})
ax = sns.catplot(x=bar_col, y='count in %', data=df, hue=hue_col, kind='bar', order=scaled)
解决方案
有一种更简单的方法来实现此功能,使用subplots
代替figure
,当您使用该set_tight_layout()
方法时,这会自动更改轴的位置以使您的图形看起来更好,并确保没有任何轴名称被截断。解决此问题的最快方法是在方法之前定义轴set_tight_layout()
,以便figsize
参数覆盖它。
改变:
fig = plt.figure(figsize=(12,10))
至
fig, ax = plt.subplots(figsize=(12,10))
推荐阅读
- python - BlockingIOError:[Errno 11]资源暂时不可用两个客户端一个服务器套接字python
- typescript - 如何在打字稿对象中使用自引用?
- qt - QML 设置字体大小写
- python - Statsmodels OLS 公式中的数据帧计数
- installation - v8 没有安装日志
- javascript - javascript - toFixed (444.2).toFixed(14) 中的隐蔽问题
- vnc-server - 使用tigervnc通过XDMCP访问centos7.8,键盘事件失效
- azure - 是否可以使用 Terragrunt 和 Terraform 在 Azure 上的 1 个租户中提供 2 个订阅?
- hive - Hive ACID 表抛出错误 FAILED: UnsupportedOperationException openTxn is not supported in aws EMR
- gitlab - gitlab globbing 表达式不匹配