Given a list of points x_coords,y_coords
and a their corresponding values
, I want to rasterize it onto a 2D canvas
with these specific values
. Is there a python library to do this? As an attempt I was using PIL
, however, it only allows me to fill with a single value:
draw = ImageDraw.Draw(canvas)
draw.point([*zip(x_coords, y_coords)], fill=1)
# Ideally I want to fill it with specific values:
# draw.point([*zip(x_coords, y_coords)], fill=values)
sounds like exactly what you want, scipy.interpolate.griddata
. example code included. basically you need:
# rearrange your coordinates into one array of rows
points = np.stack([x_coords, y_coords]).T
# the j-"notation" gives you 100 by 200 points in the 0..1 interval, or...
grid_x, grid_y = np.mgrid[0:1:100j, 0:1:200j]
# this gives you the specified step
grid_x, grid_y = np.mgrid[0:1:0.01, 0:1:0.01]
# resample point data according to grid
grid_z2 = griddata(points, values, (grid_x, grid_y), method='cubic')