python - 带有seaborn的for循环不显示所有图
问题描述
我一直在尝试使用 for 循环和 seaborn 绘制多个图表。尝试了不同的方法(使用子图并尝试按顺序显示它们),但我无法设法显示所有图表(我取得的最好成绩是绘制列表中的最后一个)。这是我尝试过的两种方法:
fig, ax = plt.subplots(1, 3, sharex = True) #这里只硬编码 thre 3(要绘制的切片器数量)用于测试
for i, col in enumerate(slicers):
plt.sca(ax[i])
ax[i] = sns.catplot(x = 'seq', kind = 'count', hue = col
, order = dfFirst['seq'].value_counts().index, height=6, aspect=11.7/6
, data = dfFirst) # distribution.set_xticklabels(rotation=65, horizontalalignment='right')
display(fig)
已经尝试过 plt.sca(ax[i]) 和 ax[i] = sns.catplot 之间的所有组合(如示例中所示,一次激活一个),但显示时 fig 始终显示为空。此外,我尝试使用以下方法按顺序显示数字:
for i, col in enumerate(slicers):
plt.figure(i)
sns.catplot(x = 'seq', kind = 'count', hue = col
, order = dfFirst['seq'].value_counts().index, height=6, aspect=11.7/6
, data = dfFirst) # distribution.set_xticklabels(rotation=65, horizontalalignment='right')
display(figure)
解决方案
catplot
产生自己的形象。请参阅使用 matplotlib 面向对象的接口使用 seaborn 进行绘图
因此,这里只是
for whatever:
sns.catplot(...)
plt.show()
推荐阅读
- json - 有没有办法在 Alamofire 中将数据作为对象而不是参数发送?
- r - 多元回归的输出表
- javascript - Javascript Slug 生成函数给出不正确的输出
- python - 检查数据序列列中的浮点数是否在另一列中的另一个浮点数的 0.200 范围内
- javascript - 未显示类活动
- r - 在 RStudio 中安装 readxl 时出错
- android - 用文本区域填充容器
- python - 阻止小部件相互重叠并在它们之间添加空间
- node.js - 节点提供的 ejs 文件可以使用离线引导程序吗?
- python - 我可以使用 pynput 将变量插入键盘按下吗?