Problem with numpy 2D Histogram

Jamie Mitchell jamiemitchell1604 at gmail.com
Fri Jun 20 09:54:34 EDT 2014


On Friday, June 20, 2014 9:46:29 AM UTC+1, Jamie Mitchell wrote:
> Hi folks,
> 
> 
> 
> I'm trying to plot a 2D histogram but I'm having some issues:
> 
> from pylab import *
> 
> import numpy as np
> 
> import netCDF4
> 
> hist,xedges,yedges=np.histogram2d(x,y,bins=10)
> 
> extent=[xedges[0],xedges[-1],yedges[0],yedges[-1]]
> 
> imshow(hist.T,extent=extent,interpolation='nearest')
> 
> colorbar()
> 
> show()
> 
> 
> 
> After the first line of code I get:
> 
> TypeError: Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe'
> 
> 
> 
> I'm using python2.7, x and y are type 'numpy.ndarray'
> 
> 
> 
> Cheers,
> 
> Jamie

Thanks for your help Peter.



More information about the Python-list mailing list