> Modules non standards > Seaborn > Heatmap et clustermap
Heatmap et clustermap
Heatmap
heatmap :
Pour la matrice suivante :
array([[ 0, 2, 4, 6, 8, 10],
[ 0, 3, 6, 9, 12, 15],
[ 0, 4, 8, 12, 16, 20],
[ 0, 5, 10, 15, 20, 25],
[ 0, 6, 12, 18, 24, 30],
[ 0, 7, 14, 21, 28, 35]])
ar = numpy.array([0, 1, 2, 3, 4, 5])
mat = numpy.dot(ar.reshape(1, 6).T + 2, ar.reshape(1, 6))
df = pandas.DataFrame(mat, columns = ['A', 'B', 'C', 'D', 'E', 'F'],
index = ['a', 'b', 'c', 'd', 'e', 'f'])
seaborn.heatmap(df, annot = True, cbar = True, cmap = 'plasma')
pyplot.tight_layout()
Clustermap
Utilise scipy pour faire un double clustering hierarchique.
On peut donner une array numpy ou un dataframe pandas :
ar = numpy.array([[5, 4, 5, 6, 5], [6, 3, 4, 5, 1],
[1, 6, 4, 2, 7], [4, 1, 2, 3, 0],
[2, 7, 5, 3, 8]])
df = pandas.DataFrame(ar, columns = ['A', 'B', 'C', 'D', 'E'],
index = ['a', 'b', 'c', 'd', 'e'])
seaborn.clustermap(df, cmap = 'viridis', method = 'ward')
- method = 'single' : méthode pour l'aggrégation (single, complete, average, ward, centroid, ...)
- metric = 'euclidean' : distance à utiliser (euclidean, cosine, correlation, canberra, cityblock, hamming, jaccard, mahalanobis, minkowski, ...).
- z_score = 0 : calcule un z-score par ligne avant de faire le clustering (z_score = 1 pour le faire par colonne).
- standard_scale = 0 : même principe qu'avec le paramètre z_score, mais en normalisant par (x - min) / (max - min)
- row_cluster = False : ne fait pas de clustering des lignes (défaut est True)
- col_cluster = False : ne fait pas de clustering des colonnes (défaut est True)
- pour supprimer les étiquettes le long de l'axe des y : g = seaborn.clustermap(...); g.ax_heatmap.yaxis.set_visible(False)
Copyright python-simple.com
programmer en python, tutoriel python, graphes en python, Aymeric Duclert