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

Heatmap

Représentation d'une matrice sous forme de heatmap (un carré par valeur, et une couleur qui dépend de cette valeur) : mat = [[1, 2, 3, 1], [4, 5, 6, 4], [7, 7, 10, 10]] pyplot.matshow(mat) pyplot.title('exemple de matrice avec couleurs par defaut')
Exemple avec 2 heatmaps sur la même figure : figure = pyplot.figure() axes = figure.add_subplot(2, 1, 1) mat = [[1, 2, 3, 1], [4, 5, 6, 4], [8, 7, 10, 9]] axes.matshow(mat, cmap = pyplot.cm.gist_rainbow) axes.set_xticks(range(4)) axes.set_xticklabels(['A', 'B', 'C', 'D']) axes.set_yticks(range(3)) axes.set_yticklabels(['a', 'b', 'c']) axes.set_title('origine en haut a gauche') axes = figure.add_subplot(2, 1, 2) axes.matshow(mat, origin = 'lower', cmap = pyplot.cm.gist_rainbow) axes.set_xticks(range(4)) axes.set_xticklabels(['A', 'B', 'C', 'D']) axes.set_yticks(range(3)) axes.set_yticklabels(['a', 'b', 'c']) axes.set_title('origine en bas a gauche')

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