Mis a jour le 2024-03-17, 13:4

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 = 'Spectral_r', method = 'ward')
df = pandas.DataFrame({'A': [2, 3, 5, 6], 'B': [7, 4, 9, 12], 'C': [1, 3, 4, 8]}, index = ['a', 'b', 'c', 'd']) g = seaborn.clustermap(df, cmap = 'RdBu_r', method = 'average', figsize = (5, 5), cbar_kws = {'ticks': [-1, 0, 1], 'label': 'myLabel'}, row_colors = ['red', 'green', 'red', 'red'], col_colors = ['blue', 'blue', 'gray'], z_score = 1, center = 0, dendrogram_ratio = (0.05, 0.3), colors_ratio = (0.05, 0.01), cbar_pos = (1, 0.2, 0.2, 0.5)) g.ax_heatmap.tick_params('x', rotation = 90) for lab in g.ax_heatmap.get_xticklabels(): lab.set_fontsize(20) lab.set_color('gray') lab.set_fontfamily('monospace')

Copyright python-simple.com
programmer en python, tutoriel python, graphes en python, Aymeric Duclert