Problème pour faire une heatmap Hexagonal à partir d'une matrice de densité
Bonjour,
Je voudrais faire un graphique qui fait correspondre à l'intensité d'une grandeur variable une gamme de tons en python.
Le problème c'est que j'ai une matrice de densité et j'aimerais le faire avec des cellules hexagonales.
Je sais utiliser pcoloc pour le faire avec des cellules carrés.
J'ai vu que l'on pouvait utiliser hexbin, le problème c'est que cette fonction utilise un histogramme 2-D pour faire le graphique hors moi j'ai une matrice d'intensité.
Pouvez vous m'aider?
Merci beaucoup :)
Je vous mets ci dessous un code pour hexbin
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
n = 100000
x = np.random.standard_normal(n)
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)
xmin = x.min()
xmax = x.max()
ymin = y.min()
ymax = y.max()
fig, axs = plt.subplots(ncols=2, sharey=True, figsize=(7, 4))
fig.subplots_adjust(hspace=0.5, left=0.07, right=0.93)
ax = axs[0]
hb = ax.hexbin(x, y, gridsize=50, cmap='hot')
ax.axis([xmin, xmax, ymin, ymax])
ax.set_title("Hexagon binning")
cb = fig.colorbar(hb, ax=ax)
cb.set_label('counts')
ax = axs[1]
hb = ax.hexbin(x, y, gridsize=50, bins='log', cmap='hot')
ax.axis([xmin, xmax, ymin, ymax])
ax.set_title("With a log color scale")
cb = fig.colorbar(hb, ax=ax)
cb.set_label('log10(N)')
plt.show() |