for seaborn循环未显示所有情节

时间:2019-08-14 15:54:27

标签: python for-loop seaborn databricks

我一直在尝试使用for循环和seaborn绘制多个图形。尝试了不同的方法(使用子图并尝试按顺序显示它们),但我无法设法显示所有图形(我获得的最好成绩是绘制列表中的最后一个图)。这是我尝试过的两种方法:

fig,ax = plt.subplots(1,3,sharex = True)#只需在此处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)

1 个答案:

答案 0 :(得分:0)

catplot产生自己的图形。参见Plotting with seaborn using the matplotlib object-oriented interface

因此,就在这里

for whatever:
    sns.catplot(...)

plt.show()