🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

Collect coordinates of shape drawn in python

Hi,

I have a simple scatter plot on top of which I hand-annotated some shapes using drawopenpath. Now I want to collect the coordinates of the shape that I have drawn. I realize it can be done with “callbacks”, but I am not sure how. Can someone please help?

fig1 = px.scatter(df, x = "xcoord", y = "ycoord")
fig1.update_traces(marker=dict(size=2))
fig2 = px.scatter(boundary_df, x="x", y="y")
fig2.update_traces(marker=dict(size=3,color="Red"))
fig3 = go.Figure(data=fig1.data+ fig2.data, 
                 layout=go.Layout(width=500,height=500))

fig3.update_layout(
    dragmode='drawrect',
    newshape=dict(line_color='cyan'),
    title_text='Drag to add annotations - use modebar to change drawing tool'
)

fig3.show(config={'modeBarButtonsToAdd':[
                                        'reload',
                                        'drawopenpath',
                                        'eraseshape'
                                       ]})

My code with two dataframes.

It is easy to do with the EditControl in dash-leaflet :slight_smile:

http://dash-leaflet.herokuapp.com/#edit_control

Thanks for replying, but I don’t see how? From the page

The EditControl makes it possible to draw and edit vectors and markers. It is powered by Leaflet.draw, but with a custom Dash integration that exposes the visible geometries in geojson format via a geojson property and the edit actions via an action property.

So it collects the points inside the boundary not the coordinates of the shape that I have drawn. Am I missing something?

No, it collects the points you have drawn (the boundary itself, i.e. you get a polygon). That’s what you want, right? Or did I misunderstand? :smiley:

Well I want the coordinates of the path drawn by open drawing. But getting polygon would be one step, would it work for non-map data?

What du you mean by ‘open drawing’? What other information than the polygon coordinates do you need?

drawopenpath creates a Path object instead of a polygon.