You can use the Python image library if you don't mind dependency. If for a 2D array numpy data and an array of poly coordinates of a polygon (with shape (n, 2)), this will draw a polygon filled with the value 0 in the array:
img = Image.fromarray(data) draw = ImageDraw.Draw(img) draw.polygon([tuple(p) for p in poly], fill=0) new_data = np.asarray(img)
There is a separate demo here:
import numpy as np import matplotlib.pyplot as plt
This script generates this graph:

Warren weckesser
source share