I'm looking for a way to fine tune the color of individual cells in a hexbin plot.
I have tried to use the method set_facecolors
from PolyCollection
to alter the color of an individual cell but this does not appear to work.
Example: this should result in a hexbin with a red cell in the center:
import numpy as np
import matplotlib.pyplot as plt
x = y = np.linspace(0.,1.,10)
pts=np.vstack(np.meshgrid(x,y,indexing='ij')).reshape(2,-1).T
z = np.zeros_like(pts[:,0])
fig, ax = plt.subplots(figsize=(3, 3))
hb = ax.hexbin(pts[:,0],pts[:,1], C=z, gridsize=(5,3), vmin=-1., edgecolors='white')
ax.set_xlim([0,1])
ax.set_ylim([0,1])
ax.figure.canvas.draw()
fcolors = hb.get_facecolors()
fcolors[31] = [1., 0., 0., 1.]
hb.set_facecolors(fcolors)
plt.show()
Any idea on how to set the facecolor of individual cells?