[SciPy-user] KDE 2D, problem on axis and pylab.scatter

F. B. fusion_energy@hotmail....
Thu Aug 28 01:26:00 CDT 2008

```

Hello
I have a problem with this code.

-------------------------------------------------------------------
import numpy as np
from numpy import array
from numpy import log
import scipy.stats as stats
from matplotlib.pyplot import imshow
import pylab as pl
import copy

f=open("datain.txt","r")

xvect=[]
yvect=[]

for i in range(len(xyval)):
if (i< (len(xyval)/2)  ):
yvect.append(float(xyval[i]))
else:
xvect.append(  log(  float(xyval[i])   )  )

rvs=np.r_[[xvect],[yvect]]

#yvalues=array(yvect)
#xvalues=array(xvect)
#xmin=xvalues.min()
#xmax=xvalues.max()
#ymin=yvalues.min()
#ymax=yvalues.max()
#stepx=xmax/256
#stepy=ymax/256

print
"xmin: "+str(xmin)+"   xmax: "+str(xmax)+"  stepx: "+str(stepx)+"
ymin: "+str(ymin)+" ymax: "+str(ymax)+" stepy: "+str(stepy)

#x_flat=np.arange(0,xmax,stepx)
#y_flat=np.arange(0,ymax,stepy)

x_flat=np.arange(-25,-15,0.1)
y_flat=np.arange(0,900,1)

kde = stats.kde.gaussian_kde(rvs) #rvs.T = [[....],[....]]

x,y = np.meshgrid(x_flat,y_flat)

grid_coords = np.append(x.reshape(-1,1),y.reshape(-1,1),axis=1)

z = kde(grid_coords.T)
z = z.reshape(len(y_flat),len(x_flat))

pl.hold(True)
contplot=pl.contourf(z,20)
ax=copy.deepcopy(pl.axis())
pl.scatter(xvect,yvect,c='y')
pl.axis(ax)
print pl.axis()
pl.show()
-------------------------------------------------------------------

I need to create a kernel density distribution of my data but the result that I obtain is strange.
From
readlines I read the x values that are in a range from 10**-7 to
10**-12, but for them (as you can see) I use the logarithm and then
they go from -25 to -15.
My y values are in range 50 to 1000 more or less.

There are some problems, first of all, the range of the values.
Using   x_flat=np.arange(-25,-15,0.1) I have a problem with the value of the X axis.
In
the graph that I obtain, the minimum value in x is zero, and the
maximum one is one hundred, but it is supposed to be between -25 and
-15.
(you can see that the length of x_flat is 100).

The
other problem that I have is the scatter plot. I should plot my
data over the KDE but I cannot do that and I don't know why.
However the shape of the KDE is that I expect.

If someone could gently help me I would really appreciate it.

Thanks and best regards
F. B.

_________________________________________________________________
Windows Live Mail: il programma gratuito per gestire tutta la tua posta!
http://get.live.com/wlmail/overview
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20080828/42ec8716/attachment.html
```