Pardon my ignorance but somehow all interpolation, smoothing of 2D maps solutions require a relationship Z~f(x,y)
and does not fit my problem. This is closest to my problem : smoothing surface plot from matrix
I have three columns of same lengths: X coordinates, Y coordinates, and the Z-value
I can plot a scatterplot like this
with Z as the filler / colormap, but it looks like points on a grid with regular intervals.
I want to interpolate and smooth them to fill in the gaps between the gridpoints but I don't know what the Z~f(x,y)
is. Is there a way to achieve this?
UPDATE
credit to @Wombatz for the interpolation (see solution below). I have added his contribution to my code and figured out how to resample 1D-array Z
-col to a 2D-array that fits my (x,y)
array. My code below:
import matplotlib.pyplot as plt
from matplotlib.pyplot import imshow
from scipy.interpolate import griddata
import numpy as np
x = [0,0,1,1,2,2] #1D
y = [0,1,0,1,0,1] #1D
Z = [1,2,3,4,5,6] #1D
extent = (min(x), max(x), min(y), max(y))
xs,ys = np.mgrid[extent[0]:extent[1]:3j, extent[2]:extent[3]:2j] #2D x,y
Z_resampled = griddata((x, y), Z, (xs, ys)) #2D z
imshow(z_resampled, interpolation="gaussian", extent=extent, origin="lower")