崔箐坡*_*崔箐坡 4 python matplotlib seaborn
clustermap 返回一个 clustergrid,我想知道可以在 clustergrid 'g' 后面添加的所有选项,如下代码所示。我在seaborn中找不到详细的文档。有谁可以帮忙\xef\xbc\x9f
\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\niris = sns.load_dataset("iris")\ng = sns.clustermap(iris, col_cluster=False, yticklabels=False)\ng.cax.set_position([.15, .2, .03, .45])\ng.ax_heatmap.XXX\n\n\nRun Code Online (Sandbox Code Playgroud)\n
Python中有一些工具可以获取对象的信息。部分问题是您的代码在创建g, 时挂起(这当然可能就是您需要文档的原因!)。seaborn但使用文档中的示例:
import seaborn as sns; sns.set(color_codes=True)
iris = sns.load_dataset("iris")
species = iris.pop("species")
g = sns.clustermap(iris)
Run Code Online (Sandbox Code Playgroud)
您可以执行以下操作dir(g)来获取其所有属性:
['__class__',
'__delattr__',
'__dict__',
'__dir__',
'__doc__',
...
'row_colors',
'savefig',
'set',
'standard_scale',
'z_score']
Run Code Online (Sandbox Code Playgroud)
您还可以致电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:
...
...
...
Run Code Online (Sandbox Code Playgroud)
您可以使用type(g)来获取完整的对象类型:
seaborn.matrix.ClusterGrid
Run Code Online (Sandbox Code Playgroud)
它可以向seaborn您展示通过源代码获取其定义的路径。
您还可以使用内置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={})
Run Code Online (Sandbox Code Playgroud)
我也找不到记录的在线文档。