Annotated heatmap Example#

Here shows how to draw annotated heatmap

import numpy as np
import pandas as pd
import milkviz as mv

np.random.seed(0)

First let’s create some random data#

import seaborn as sns

p = sns.load_dataset("penguins").dropna()
df = p.set_index(["species", "island", "sex"])
data = np.random.randn(*df.to_numpy().shape)
df = pd.DataFrame(data=data, columns=df.columns, index=df.index)
df.columns.name = "col"
df
col bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
species island sex
Adelie Torgersen Male 1.764052 0.400157 0.978738 2.240893
Female 1.867558 -0.977278 0.950088 -0.151357
Female -0.103219 0.410599 0.144044 1.454274
Female 0.761038 0.121675 0.443863 0.333674
Male 1.494079 -0.205158 0.313068 -0.854096
... ... ... ... ... ... ...
Gentoo Biscoe Female -0.255958 -0.348046 -0.782367 0.625119
Female -0.813596 -0.521642 -0.073120 -1.297380
Male -0.324935 -0.711306 -0.388154 -0.059928
Female -0.799914 -0.220076 1.308669 -0.025799
Male 1.145262 0.346494 0.774161 -0.774459

333 rows × 4 columns



Create the heatmap#

mv.anno_clustermap(df, row_colors=["species", "island", "sex"],
                   col_label="col", z_score=0)
plot anno heatmap
<seaborn.matrix.ClusterGrid object at 0x7f1e7b527e20>

Total running time of the script: ( 0 minutes 2.124 seconds)

Gallery generated by Sphinx-Gallery