[Scilab-users] hist3d & density plots
Stéphane Mottelet
stephane.mottelet at utc.fr
Mon Sep 10 11:00:37 CEST 2018
Le 10/09/2018 à 09:56, antoine.monmayrant at laas.fr 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.
This feature is fixed in scilab-branch-6.0:
S.
--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet
More information about the users
mailing list