marsilea.base.ClusterBoard#
- class marsilea.base.ClusterBoard(cluster_data, width=None, height=None, name=None, margin=0.2)#
Bases:
WhiteBoard- add_dendrogram(side, method=None, metric=None, linkage=None, add_meta=True, add_base=True, add_divider=True, meta_color=None, linewidth=None, colors=None, divider_style='--', meta_ratio=0.2, show=True, name=None, size=0.5, pad=0.0, get_meta_center=None)#
Run cluster and add dendrogram
Note
method and metric only works when you add the first row/col dendrogram.
If add_meta=False and add_base=False, the dendrogram axes will not be created.
- Parameters:
- side
- methodstr
See scipy’s
linkage- metricstr
See scipy’s
linkage- linkagendarray
Precomputed linkage matrix. See scipy’s
linkagefor specific format.- add_metaNone | bool
By default, add_meta is set to False if the linkage is provided, otherwise True. If the data is split, a meta dendrogram can be drawn for data chunks. The mean value of the data chunk is used to calculate linkage matrix for meta dendrogram.
- add_baseNone | bool
By default, add_meta is set to False if the linkage is provided, otherwise True. Draw the base dendrogram for each data chunk. You can turn this off if the base dendrogram is too crowded.
- add_dividerbool
Draw a divide line that tells the difference between base and meta dendrogram.
- divider_stylestr, default: “–”
The line style of the divide line
- meta_colorcolor
The color of the meta dendrogram
- meta_ratiofloat
The size of meta dendrogram relative to the base dendrogram
- linewidthfloat
The linewidth for every dendrogram and divide line
- colorscolor, array of color
If only one color is specified, it will be applied to every dendrogram. If an array of color is specified, it will be applied to each base dendrogram.
- showbool
If False, the dendrogram will not be drawn and the axes will not be created.
- namestr
The name of the dendrogram axes
- sizefloat
- padfloat
- get_meta_center: callable
A function to calculate the centroid of data. It should accept a 2D numpy array as input and return a 1D numpy array of the same length as the number of columns in the input, representing the centroid. The default will use the mean values.
Examples
You can change how the linkage matrix is calculated
>>> data = np.random.rand(10, 11) >>> import marsilea as ma >>> h = ma.Heatmap(data) >>> h.add_dendrogram("left", method="ward", colors="green") >>> h.render()
Only show the meta dendrogram to avoid crowded dendrogram
>>> h = ma.Heatmap(data) >>> h.hsplit(cut=[4, 8]) >>> h.add_dendrogram("left", add_base=False) >>> h.render()
Change color for each base dendrogram
>>> h = ma.Heatmap(data) >>> h.hsplit(cut=[4, 8]) >>> h.add_dendrogram("left", colors=["#5470c6", "#91cc75", "#fac858"]) >>> h.render()
- property col_cluster#
- get_col_linkage()#
- get_deform()#
- get_row_linkage()#
- hsplit(cut=None, labels=None, order=None, spacing=0.01)#
- property row_cluster#
- square = False#
- vsplit(cut=None, labels=None, order=None, spacing=0.01)#