Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I normalize a hexbin plot?

I have two distributions within a hexbin plot, like the one shown: enter image description here

One distributions has a max value of about 4000, while the other has a max value of about 2500. The plotting colours are therefore different.

I was thinking I could normalize it if I knew the max value of the hexbin plot. How do I know how many points are within the max hexbin other than looking at the colorbar? I am using matplotlib.pyplot.hexbin

like image 991
Paul Avatar asked Jul 25 '12 08:07

Paul


1 Answers

You can get the min and max of the norm which is what is used to normalize the data for color picking.

hb = plt.hexbin(x, y)
print hb.norm.vmin, hb.norm.vmax

You could then go on to pass a norm with this information to the second plot. The problem with this is that the first plot must have more range than the second, otherwise the second plot will not all be colored.

Alternatively, and preferably, you can construct a norm which you pass to the hexbin function for both of your plots:

norm = plt.normalize(min_v, max_v)
hb1 = plt.hexbin(x1, y1, norm=norm)
hb2 = plt.hexbin(x2, y2, norm=norm)

HTH,

like image 135
pelson Avatar answered Nov 11 '22 09:11

pelson