Exemples de comment visualiser (tracer) un tableau numpy (i.e. matrice 2D) en python en utilisant seaborn:
Créer un tableau avec numpy
Créons d'abord un tableau quelconque avec numpy:
import numpy as npdata = np.random.randint(10, size=(10,8))print(data)
donne par exemple
[[9 6 7 8 6 4 4 9][1 1 4 0 4 6 0 1][6 9 2 2 8 6 8 0][9 8 9 1 4 2 2 3][3 3 4 8 9 9 5 4][5 4 2 8 7 3 4 7][0 1 0 0 0 3 0 2][7 2 6 5 4 4 5 2][5 2 6 5 6 2 2 2][3 1 0 5 9 2 2 2]]
Tracer un tableau avec seaborn
Si vous souhaitez visualiser rapidement un tableau pas trop grand, une solution consiste à utiliser seaborn avec heatmap, exemple:
import seaborn as sns; sns.set()import matplotlib.pyplot as pltax = sns.heatmap(data, annot=True, fmt="d")plt.title("How to visualize (plot) \n a numpy array in python using seaborn ?",fontsize=12)plt.savefig("visualize_numpy_array_01.png", bbox_inches='tight', dpi=100)plt.show()
donne

Supprimer la colorbar
ax = sns.heatmap(data, annot=True, fmt="d", cbar=None)plt.title("How to visualize (plot) \n a numpy array in python using seaborn ?",fontsize=12)plt.savefig("visualize_numpy_array_02.png", bbox_inches='tight', dpi=100, )plt.show()

Supprimer les labels sur les axes
ax = sns.heatmap(data, annot=True, fmt="d", cbar=None, xticklabels=False, yticklabels=False)plt.title("How to visualize (plot) \n a numpy array in python using seaborn ?",fontsize=12)plt.savefig("visualize_numpy_array_03.png", bbox_inches='tight', dpi=100, )plt.show()

