hexbin....matplotlib.collections.PolyCollection

Is there a way to get at all the paths with matplotlib1.3.0?

I use hexbin and create the following output: “hex31mm”

In [42]: type(hex31mm)

Out[42]: matplotlib.collections.PolyCollection

I am trying to replicate my use of the method “get_paths” under “matplotlib 1.1.0” for the function below but with the newer version of “matplotlib 3.0.1”

“get_paths” under matplotlib 3.0.1, yields 802 distinct paths as below:

In [41]: len(hex31mm.get_paths())

Out[41]: 802

BUT “get_paths” under matplotlib 1.3.0, for this same object “hex31mm” yields only one path as below:

In[1] len(hex31mm.get_paths())

Out[1]: 1

I am sure the information for all paths are part of the object even in matplotlib 1.3.0 because the hexbin figure that plots up onto the screen is the same under both matplotlib versions however I require the hexbin centres, hence my insistance of use on the “get_path” method.

The function I am trying to replicate works fine in matplotlib1.1.0 but not under matplotlib1.3.0 (is below). It is supposed to return an array (n,2), and each element of that array is the centre (x,y) of n hexbins:

def get_centres(hexbin _output):
paths=hexbin _output.get_paths()
v=paths[0].vertices [:-1]
vx,vy =v.T
idx =[3,0,5,2]
xmin,xmax,ymin,ymax=vx[idx[0]],vx[idx[1]],vy[idx[2]],vy[idx [3]]
half_width_x=abs(xmax-xmin )/2.0
half_width_y=abs(ymax-ymin )/2.0
centres=[]
for i in xrange(len (paths)):
cx = paths[i].vertices[idx [0],0]+half_width_x
cy = paths[i].vertices[idx [2],1]+half_width_y
centres.append((cx,cy ))
return asarray(centres)

best regards,

  • Sebastian