首页 > 解决方案 > 使用 Seaborn 填充子图 Python

问题描述

当尝试创建一些子图然后在使用 Seaborn 时填充它们时,我将所有内容都绘制在同一个子图中。这个最小的工作示例完全重现了我的问题。我希望我的 tseries 变量的每个不同的第一个索引都绘制在不同的子图中,因为我认为我的代码通过调用不同的轴来显示。如果您对我犯错误的地方有任何建议,出了什么问题,请告诉我,任何建议都非常感谢!

谢谢!

import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
%matplotlib inline


tseries = np.random.random((3,100))
labels = np.random.randint(1,4,100)

fig, ax = plt.subplots(1, 3, figsize = (50,25))
k = 3
for clusteridx in range(1,k+1):
    ax[0] = sns.kdeplot(tseries[0,labels==clusteridx],shade=True,label='cluster '+str(clusteridx))
for clusteridx in range(1,k+1):
    ax[1] = sns.kdeplot(tseries[1,labels==clusteridx],shade=True,label='cluster '+str(clusteridx))
for clusteridx in range(1,k+1):
    ax[2] = sns.kdeplot(tseries[1,labels==clusteridx],shade=True,label='cluster '+str(clusteridx))


标签: python-3.xmatplotlibseabornsubplot

解决方案


推荐阅读