With ScatteredInterpolation.jl
we can get from the three vectors, x, y, z, a matrix zg, consisting in interpolated values at the points of a meshgrid associated to linear grids, xg and yg.
As long as we don’t know what interpolation method is used by
plotly.js
, we cannot obtain exactly the same contours. Among different methods of interpolation from ScatteredInterpolation.jl
, the radial basis function method with Multiquadratic
basis function defines a Plots.contourf
somehow similar to PlotlyJS.contour
.
using ScatteredInterpolation, Plots, ColorSchemes
let
x = [1, 2, 3, 1]
y = [1, 1, 2, 2]
z = [1.0, 2, 3, 4]
points = stack(zip(x,y))
itp = interpolate(Multiquadratic(), points, z);
xm, xM = extrema(x)
ym, yM = extrema(y)
n = 50
m = 25
xg = range(xm, xM, n)
yg = range(ym, yM, m)
X = [s for t in yg, s in xg] #size(X) is (m,n)
Y = [t for t in yg, s in xg] # size(Y) is also (m,n)
gridP = stack(vec([[x, y] for (x,y) in zip(X, Y)])) #2 x m*n - matrix; each column is a grid point
interpolated = evaluate(itp, gridP)
zg = reshape(interpolated, m, n)
p = Plots.contourf(xg, yg, zg; levels=6, c=cgrad(ColorSchemes.plasma))
end