Extract coordinates inside a polygon shape drawn with dcc.Graph dragmode

Hey @matt.sd.watson welcome to the forums.

I extracted the coordinates like this in the past:

import re

def extract(closedpath: str) -> list[float]:
    path = re.split('[a-zA-Z]', closedpath)
    path = [point for point in path if point]

    # initiate variables
    x = []
    y = []

    for point in path:
        point_x, point_y = map(float, point.split(','))
        x.append(point_x)
        y.append(point_y)
    return x,y

usage:

string = "M291.94094488188983,299.9798228346457L314.61811023622056,277.30265748031496L351.468503937008,277.30265748031496L367.53149606299223,283.91683070866145L387.3740157480316,290.5310039370079L404.3818897637796,307.5388779527559Z"

x, y = extract(string)

As for the second part of your question, this might be helpful:

Search for the text passage:

we use the function skimage.draw.polygon to obtain the coordinates of pixels covered by the path
then we use the function scipy.ndimage.binary_fill_holes in order to set to True the pixels enclosed by the path.

EDIT: reading the linked example it sounds pretty similar to what you want to do…