julia# 2D interpolation in Julia

I have two arrays of Float64: `arr_x`

and `arr_y`

. I have a 2D array `arr_z`

storing some function z(x,y) computed on the set of points (x,y) with `x`

in `arr_x`

, `y`

in `arr_y`

.

How can I do a 2D interpolation of `arr_z`

using `arr_x`

and `arr_y`

? That is, I would like a function `itp_z(x,y)`

which does the equivalent of linear interpolation but now in 2D on the array arr_z.

Solution

Interpolations.jl should work for that:

```
using Interpolations, Plots
# Data
x = range(-2, 3, length=20)
y = range(3, 4, length=10)
z = @. cos(x) + sin(y')
# Interpolation object (caches coefficients and such)
itp = LinearInterpolation((x, y), z)
# Fine grid
x2 = range(extrema(x)..., length=300)
y2 = range(extrema(y)..., length=200)
# Interpolate
z2 = [itp(x,y) for y in y2, x in x2]
# Plot
p = heatmap(x2, y2, z2, clim=(-2,2), title="Interpolated heatmap")
scatter!(p, [x for _ in y for x in x], [y for y in y for _ in x], zcolor=z[:]; lab="original data", clim=(-2,2))
```

- Julia: is there a function to obtain the version number of a package?
- Get permutation of one array based on the size ordering of the other array
- Making Julia show different plots in different windows
- How to get equally scaled axes with Plots in Julia
- Scatter plot of two rows of a DataFrame in Julia using Plotly
- Adding constraints to jump model from dict
- Non-iterable argument to a function called by Julia `map`?
- Compute row sums and column sums efficiently in Julia
- Julia copying folder into an existing folder
- How to replace a function in Julia?
- How to force Julia to use multiple threads for matrix multiplication?
- Can Revise.jl handle `ERROR: LoadError: invalid redefinition of constant`?
- Define piecewise function with automatic broadcasting in Julia
- julia Handling time difference in dataframe
- Fast tensor-dot on sparse arrays with GPU in any programming language?
- Why do allocations occur during broadcasting assignment to a preallocated array?
- Comparing RK4 to Euler method
- How to put even numbers from matrix in separate vector in Julia?
- Number of iterations performed by a for-loop in Julia
- Can I redefine a function, but still use the old definition within the new definition?
- how do I use analytical form as gradient with ! function?
- Julia equivalent to R `as.numeric()`
- Why does Float16(1.1)-Float16(1)=Float16(0.0996)?
- Julia manual and defining an infix operator
- In Julia, how to convert a unsigned number to a signed number like in C?
- Julia Package DataFrames 1.6.1 doesn't recognize old version DataFrames 1.3.4 file
- Convert Julia DataFrame to an array of bytes for compression
- How to suppress svg output by IJulia in Jupyter notebooks
- how to get the documentation of a julia function in a vscode notebook?
- Passing command-line arguments to a Pluto Notebook