【问题标题】:change specific row size of seaborn clustermap更改 seaborn clustermap 的特定行大小
【发布时间】:2020-09-27 10:17:22
【问题描述】:

我使用 seaborn clustermap 来可视化聚类结果(每一行代表一个不同的聚类)。另外,我有总数据的百分比分配给每个集群的数据。我想知道如何将该信息添加到集群图中。例如,是否可以更改 clustermap 的行高,使每行的高度与其所代表的集群大小成正比?

【问题讨论】:

    标签: python seaborn cluster-analysis visualization


    【解决方案1】:

    查看 Seaborn 文档和生成的 Matplotlib 文档,我认为使用 seaborn 是不可能的。 matplotlib 库将允许您以您喜欢的任何方式创建 pcolormesh(Seaborn 使用的)。

    例如,看下面的例子。您可以指定 x 和 y 值,这些值确定给定点的行/列的高度和宽度。因此,使用 matplotlib,您可以传入您谈到的宽度值并创建您的颜色网格,尽管整个过程不会像使用 sns.clustermap(iris)! 那样简单。有关详细信息,请参阅下面的代码。

     # evenly spaced integers
    x1 = np.array([1,2,3,4,5,6])
    y1 = np.array([1,2,3,4,5,6])
    
    # uneven spacing between each item
    x2 = np.array([1,1.5,3.8,4,5,6])
    y2 = np.array([1,1.5,3,4.4,5,6])
    
    # fill with random data
    z = np.random.randint(0,32,25).reshape(nrows,ncols)
    
    # create plots
    fig, (ax1,ax2) = plt.subplots(nrows=2, ncols=1,figsize=(10,10))
    
    ax1.pcolormesh(x1, y1, z, cmap='Blues', edgecolors='black')
    ax2.pcolormesh(x2, y2, z, cmap='Blues', edgecolors='black')
    plt.show()
    

    结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-06
      • 2015-12-28
      • 2017-06-30
      • 2018-12-26
      • 2016-09-11
      • 2016-04-20
      • 2020-09-01
      • 2023-01-10
      相关资源
      最近更新 更多