Does anybody know where could I find the documentaton about the clustergrid in seaborn clustermap?

Viewed 1800

The clustermap returns a clustergrid, I want to know all the option I could add behind the clustergrid 'g' as the code showed below. I could not found the detailed documentation in seaborn. Does anybody could help?

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


2 Answers

There are tools to get information of objects in Python. Part of the problem is that your code gets hung up at the creation of g, (which of course is maybe why you want documentation!). But using the example from the seaborn docs:

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

You can do dir(g) to get all its attributes:

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

You can also call help(g) to get the docstring for 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:
...
...
...

You can use type(g) to get the full object type:

seaborn.matrix.ClusterGrid

Which can show you the path through the seaborn source to get its definition here.

You could also use the built-in inspect module to get more information for 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={})

I also cannot find online documentation for the record.

I had the same problem, so I decided to go to the code of Seaborn in github.
Once there, a quick tricky is to use the github1s.com for searching the repo using VSCode.

You can find the code here: seaborn/matrix.py#L795. I guess that this can help orient better.

Even though seaborn does not have full documentation yet, the Clustermap is really pretty and useful.

Related