Julia version of Matplotlib griddata?

622 views
Skip to first unread message

Kaj Wiik

unread,
Jul 8, 2016, 6:57:51 PM7/8/16
to julia-users
Is there a Julia version of irregularly spaced data gridding that does
zi = griddata(x,y,z,xi,yi), i.e. all arguments are 1d vectors? It seems that Julia interp and contour packages require x, y, z[x,y].


Thanks,
Kaj

Steven G. Johnson

unread,
Jul 8, 2016, 7:00:29 PM7/8/16
to julia-users
(You can always call the Matplotlib function from Julia via PyCall.)

Kaj Wiik

unread,
Jul 8, 2016, 7:25:37 PM7/8/16
to julia-users
Yes, I tried that but for some reason, couldn't get natgrid recognized by matplotlib... One way would try to call natgrid library (libncarg) directly...

Thanks,
Kaj
Message has been deleted

Josef Heinen

unread,
Jul 9, 2016, 4:02:23 AM7/9/16
to julia-users
You can use the GR framework, e.g.

srand(0)
xd = -2 + 4 * rand(100)
yd = -2 + 4 * rand(100)
zd = [Float64(xd[i] * exp(-xd[i]^2 - yd[i]^2)) for i = 1:100]

using GR
contour(xd, yd, zd, colormap=44)


If you only need the gridded data, use the GR gridit function, e.g. (to obtain a 200 x 200 grid):

x, y, z = GR.gridit(xd, yd, zd, 200, 200)

Kaj Wiik

unread,
Jul 13, 2016, 3:58:16 PM7/13/16
to julia-users
Thanks Josef.

I tried GR contour but got identical datapoint errors. It seems that it's not trivial to use unique() other than vectors...could not get it working. In fact it seems that the reported datapoints are not in fact identical:

julia> contour(c[1,:],c[2,:],c[3,:])
 ***   IDENTICAL DATA POINTS.
   NDP =12629   IP1 =    1   IP2 =  346   XD=1.02114e-99   YD=0.478687
 ERROR DETECTED IN ROUTINE   IDTANG.

julia> c[:,1]
3-element Array{Float64,1}:
     1.02114e-99
     0.478687   
 56193.8        

julia> c[:,346]
3-element Array{Float64,1}:
     1.38697e-84
     0.477974   
 56196.2        


I tried also to call natgrid directly but it seems to be a can of worms.

Kaj

Kaj Wiik

unread,
Jul 14, 2016, 5:11:57 AM7/14/16
to julia-users
I dug this problem bit deeper, it seems that my unique is working but GR.contour seems to be complaining even of close coordinates. I tried converting everything to Float32 but that didn't help either:

julia> contour(cf[3,:],cf[2,:],cf[1,:])
 ***   IDENTICAL DATA POINTS.
   NDP =12629   IP1 =   23   IP2 = 3286   XD=56192.9   YD=0.55634
 ERROR DETECTED IN ROUTINE   IDTANG.

julia> cf[:,[23,3286]]
3x2 Array{Float32,2}:
     0.0          6.64646e-20
     0.55634      0.555965   
 56192.9      56192.9        


Strange...

Kaj Wiik

unread,
Jul 14, 2016, 5:13:25 AM7/14/16
to julia-users
Forgot to mention that in the first GR.contour attempt I had x and z swapped...
Reply all
Reply to author
Forward
0 new messages