Le 10/09/2018 à 11:00, Stéphane Mottelet a écrit :
Le 10/09/2018 à 09:56, [email protected] a écrit :
Hi all,

I'm trying to plot the density of scatter points in (x,y).
Basically, I have a huge Xvec and a huge Yvec of same size that represents the position of a huge number of points in a 2D plane. I would like to get a density plot, that is given a certain grid, a 2D plot representing the number of scatter points within a each cell of the grid.
In matplotib, this corresponds to functions like "hist2d" and "hexbin".
Is there any equivalent in Scilab?
Or do I have to calculate by hand my density matrix and then use graplot or contourfill to plot my density? Any pointer at the least inefficient way to do this calculation is more than welcome...

Thank you in advance for your help,


Antoine

Hello Antoine,

The most efficient at the Scilab level would be to use the incremental feature of "sparse":

function d=bins2d(x,y,xbins,ybins)
     n = size(x,"*");
    [ix,cx] = dsearch(x,xbins);
    [iy,cy] = dsearch(y,ybins);
    kin = find((ix>0) & (iy>0));
    d = full(sparse([ix(kin) iy(kin)], ones(kin), [size(xbins,"*")-1, size(ybins,"*")-1]));
end

x = rand(10000,1,'normal');
y = rand(10000,1,'normal');

--> d = bins2d(x,y,-5:5,-5:5)
 d  =

   0.   0.   0.    0.     1.      0.      0.     0.    0.   0.
   0.   0.   0.    3.     4.      4.      0.     0.    0.   0.
   0.   0.   6.    31.    82.     80.     31.    2.    0.   0.
   0.   0.   24.   183.   477.    477.    200.   25.   3.   0.
   0.   5.   68.   439.   1131.   1158.   426.   57.   4.   0.
   0.   5.   91.   485.   1168.   1220.   438.   72.   3.   0.
   0.   4.   30.   190.   470.    472.    173.   21.   3.   0.
   0.   0.   6.    30.    83.     78.     24.    2.    0.   0.
   0.   1.   0.    2.     2.      3.      3.     0.    0.   0.
   0.   0.   0.    0.     0.      0.      0.     0.    0.   0.


--> sum(d)
 ans  =

   10000.
Thanks a lot, it works and is really fast even 2*10⁶ scatter points!

This feature is fixed in scilab-branch-6.0:
Huh, what do you mean? Is there a new function bins2d or hist2d in scilab-branch-6.0?

Antoine

S.


--
+++++++++++++++++++++++++++++++++++++++++++++++++++++++

 Antoine Monmayrant LAAS - CNRS
 7 avenue du Colonel Roche
 BP 54200
 31031 TOULOUSE Cedex 4
 FRANCE

 Tel:+33 5 61 33 64 59
email : [email protected]
 permanent email : [email protected]

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

_______________________________________________
users mailing list
[email protected]
http://lists.scilab.org/mailman/listinfo/users

Reply via email to