Does Plotly allow to plot geometrical shapes (Polygons) made using Shapely?

Hi, I have a pickle file containing a dictionary of geometrical polygons created using Shapely, matplotlib, and Descartes.

Is there a way to plot the above in Plotly ?
Thank you for your help in advance :slight_smile:

Additya Sharma

Sure you can! Check this link: Shapes | Python | Plotly
Basically, use go.Figure(go.Scatter(x=x, y=y, fill=β€œtoself”)) where x, y denote the polygon vertices which you can get from a Shapely polygon via x, y = Shapely_poly.exterior.coords.xy

1 Like

Thank you, this worked for me!!! This easily works when you have single polygons.

In case somebody is dealing with mulitpolygons,
mycoordslist = [list(x.exterior.coords) for x in polygon[key].geoms]

this code would provide a list with coordinates of each polygon (which is a part of the multipolygon)


if I may ask a follow-up question:

is it possible to represent integer values (in a numpy array) as colors (along with a colormap) inside the polygons ?

Thank you in advance for the help


found a workaround for this:

How do I add a colorbar to an already existing graph? - :bar_chart: Plotly / Plotly Python - Plotly Community Forum


There is a github project for plotting Shapely objects using Plotly. It support 2D and 3D plotting, control over line styles, colors and so forth.