【问题标题】:Does anybody know where could I find the documentaton about the clustergrid in seaborn clustermap?有人知道我在哪里可以找到关于 seaborn clustermap 中 clustergrid 的文档吗?
【发布时间】:2020-07-23 15:18:33
【问题描述】:

clustermap 返回一个 clustergrid,我想知道我可以在 clustergrid 'g' 后面添加的所有选项,如下所示。我在 seaborn 中找不到详细的文档。有人可以帮忙吗?

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset("iris")
g = sns.clustermap(iris, col_cluster=False, yticklabels=False)
g.cax.set_position([.15, .2, .03, .45])
g.ax_heatmap.XXX


【问题讨论】:

    标签: python matplotlib seaborn


    【解决方案1】:

    有一些工具可以在 Python 中获取对象的信息。部分问题是您的代码在创建g 时被挂起(这当然可能是您想要文档的原因!)。但是使用seaborn docs中的示例:

    import seaborn as sns; sns.set(color_codes=True)
    iris = sns.load_dataset("iris")
    species = iris.pop("species")
    g = sns.clustermap(iris)
    

    您可以通过dir(g) 获取其所有属性:

    ['__class__',
     '__delattr__',
     '__dict__',
     '__dir__',
     '__doc__',
     ...
     'row_colors',
     'savefig',
     'set',
     'standard_scale',
     'z_score']
    

    您也可以调用help(g) 来获取ClusterGrid 的文档字符串:

    class ClusterGrid(seaborn.axisgrid.Grid)
     |  ClusterGrid(data, pivot_kws=None, z_score=None, standard_scale=None, figsize=None, row_colors=None, col_colors=None, mask=None)
     |  
     |  Base class for grids of subplots.
     |  
     |  Method resolution order:
     |      ClusterGrid
     |      seaborn.axisgrid.Grid
     |      builtins.object
     |  
     |  Methods defined here:
    ...
    ...
    ...
    

    您可以使用type(g) 获取完整的对象类型:

    seaborn.matrix.ClusterGrid
    

    它可以向您显示通过seaborn 源获取其定义here 的路径。

    您还可以使用内置的inspect 模块来获取seaborn.matrix.ClusterGrid 的更多信息。

    >>>print(inspect.getsource(seaborn.matrix.ClusterGrid)) #for getting source code
    class ClusterGrid(Grid):
        def __init__(self, data, pivot_kws=None, z_score=None, standard_scale=None,
                     figsize=None, row_colors=None, col_colors=None, mask=None):
            """Grid object for organizing clustered heatmap input on to axes"""
    ...
    ...
    ...
    
    >>>print(inspect.getfullargspec(seaborn.matrix.ClusterGrid)) #for getting arguments
    FullArgSpec(args=['self', 'data', 'pivot_kws', 'z_score', 'standard_scale', 'figsize', 'row_colors', 'col_colors', 'mask'], varargs=None, varkw=None, defaults=(None, None, None, None, None, None, None), kwonlyargs=[], kwonlydefaults=None, annotations={})
    

    我也找不到在线记录文档。

    【讨论】:

      【解决方案2】:

      我也遇到了同样的问题,所以决定去github上Seaborn的代码。
      在那里,一个快速的技巧是使用github1s.com 使用 VSCode 搜索 repo。

      您可以在此处找到代码:seaborn/matrix.py#L795。我想这有助于更好地定位。

      尽管 seaborn 还没有完整的文档,但 Clustermap 确实非常漂亮和有用。

      【讨论】:

        猜你喜欢
        • 2017-12-04
        • 2011-10-06
        • 1970-01-01
        • 1970-01-01
        • 2018-06-16
        • 2012-02-27
        • 1970-01-01
        • 1970-01-01
        • 2015-08-16
        相关资源
        最近更新 更多