Dites que je veux distinguer les NaNs dans un colormap matplotlib. Puis:Masque deux groupes de valeurs dans matormlib colormap avec colorscheme progressive
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
# create a (4,5) matrix with values ranging from 0 to 19
np_data = np.arange(20).reshape((4,5)).astype(float)
# add a row with NaNs in the middle
np_data = np.insert(np_data,2,[np.nan for x in range(0,5)],axis=0)
# mask invalid data (NaNs)
np_data = np.ma.masked_invalid(np_data)
# get figure and ax objects from plot
fig, ax = plt.subplots()
# Draw an "X" on transparent values (masked values)
ax.patch.set(hatch='x', edgecolor='blue')
# get a predefined color scheme
reds_cm = plt.get_cmap("Reds")
# Plot heatmap, add a colorbar and show it
heatmap = ax.pcolor(np_data, cmap=reds_cm)
cbar = fig.colorbar(heatmap)
plt.show()
maintenant NaN sont facilement identifiables dans l'intrigue. Maintenant, disons que je veux être capable de distinguer facilement entre les NaNs, les 0 et le reste des valeurs.
Si je masque maintenant les 0, je ne serai pas capable de distinguer les NaN et les 0. Comment puis-je différencier 2 groupes de valeurs dans une palette de couleurs? Dans ce cas, NaNs d'une part et 0s de l'autre.
Des questions pertinentes ici sont http://stackoverflow.com/questions/35905393/python-leave-numpy-nan-values-from-matplotlib-heatmap-and-its-legend/35905483 # 35905483 et http://stackoverflow.com/questions/16120481/matplotlib-grayscale-heatmap-with-visually-distinct-na-squares-fields – ImportanceOfBeingErnest