我一直在尝试使用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( axi )和axi= 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)发布于 2019-08-15 00:33:31
catplot生成自己的图形。请参阅Plotting with seaborn using the matplotlib object-oriented interface
因此,这里只是
for whatever:
sns.catplot(...)
plt.show()https://stackoverflow.com/questions/57498176
复制相似问题