hexbin difference map

Any hints on how to visualize the density difference between two hexbin plot, each with x-y (2D) data?

Each set has roughly 300,000 points.
The range in x and y values for each data set are roughly similar but with slightly different density:

range x,x1: -1.222 to 3.656
range y,y1: 13.191, 18.150

So the steps:

(1) Produce the two hexbin maps:

fig1=hexbin(c_b204_jmk,c_b204_k,C = None, gridsize = 100, bins = None, xscale = ‘linear’, yscale = ‘linear’, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, edgecolors=‘none’,reduce_C_function = np.mean, mincnt=None, marginals=False)

fig2=hexbin(c_b211_jmk,c_b211_k,C = None, gridsize = 100, bins = None, xscale = ‘linear’, yscale = ‘linear’, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, edgecolors=‘none’,reduce_C_function = np.mean, mincnt=None, marginals=False)

(2) Determine the difference in the hexbin counts, with

diff_hex=fig2.get_array()-fig1.get_array()

(3) BUT when i try to plot the diff hexbin map

fig3=hexbin(c_b211_jmk,c_b211_k,C = diff_hex, gridsize = 100, bins = None, xscale = ‘linear’, yscale = ‘linear’, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, edgecolors=‘none’,reduce_C_function = np.mean, mincnt=None, marginals=False)

I obviously get a:
IndexError: index out of bounds

Because:
len(c_b211_jmk) = len(c_b211_k) != len(diff_hex),
Since diff_hex are the binned counts.

(4) Any simple way to get around this, to plot the hexbin difference counts on top of the the hexbin (c_b211_jmk,c_b211_k) distribution?

thanks in advance & with best regards,

  • Sebastian

Just do something like this:

newx = concatenate((c_b211_jmk,c_b204_jmk))
newy = concatenate((c_b211_k, c_b204_k))
newc = concatenate((ones(c_b211_k.size),-1*ones_like(c_b204_k.size)))

hexbin(newx,newy,C=newc,reduce_C_function=np.sum)

Then the color coding in each bin should be the number of counts from
b211 - number of counts from b204.

···

On Fri, May 18, 2012 at 12:11 PM, Sebastian <sebas0@...287...> wrote:

Any hints on how to visualize the density difference between two hexbin
plot, each with x-y (2D) data?

Each set has roughly 300,000 points.
The range in x and y values for each data set are roughly similar but with
slightly different density:
range x,x1: -1.222 to 3.656
range y,y1: 13.191, 18.150

So the steps:

(1) Produce the two hexbin maps:

fig1=hexbin(c_b204_jmk,c_b204_k,C = None, gridsize = 100, bins = None,
xscale = 'linear', yscale = 'linear', cmap=None, norm=None, vmin=None,
vmax=None, alpha=None, linewidths=None, edgecolors='none',reduce_C_function
= np.mean, mincnt=None, marginals=False)

fig2=hexbin(c_b211_jmk,c_b211_k,C = None, gridsize = 100, bins = None,
xscale = 'linear', yscale = 'linear', cmap=None, norm=None, vmin=None,
vmax=None, alpha=None, linewidths=None, edgecolors='none',reduce_C_function
= np.mean, mincnt=None, marginals=False)

(2) Determine the difference in the hexbin counts, with

diff_hex=fig2.get_array()-fig1.get_array()

(3) BUT when i try to plot the diff hexbin map

fig3=hexbin(c_b211_jmk,c_b211_k,C = diff_hex, gridsize = 100, bins = None,
xscale = 'linear', yscale = 'linear', cmap=None, norm=None, vmin=None,
vmax=None, alpha=None, linewidths=None, edgecolors='none',reduce_C_function
= np.mean, mincnt=None, marginals=False)

I obviously get a:
IndexError: index out of bounds

Because:
len(c_b211_jmk) = len(c_b211_k) != len(diff_hex),
Since diff_hex are the binned counts.

(4) Any simple way to get around this, to plot the hexbin difference counts
on top of the the hexbin (c_b211_jmk,c_b211_k) distribution?

thanks in advance & with best regards,
- Sebastian

--
Erik Tollerud