0

I tried it but I keep getting an error. Below is the code I use to plot:

from shapely.geometry import Polygon
import matplotlib.pyplot as plt


polygon1 = Polygon([(0,5),
                    (1,1),
                    (3,0),
                    ])

plt.plot(polygon1)
plt.show()

However, I keep getting a TypeError: float() argument must be a string or a number, not 'Polygon' when calling plt.plot(polygon1).

Georgy
  • 12,464
  • 7
  • 65
  • 73
kojo justine
  • 103
  • 1
  • 12
  • Does this answer your question? [How do I plot Shapely polygons and objects using Matplotlib?](https://stackoverflow.com/questions/55522395/how-do-i-plot-shapely-polygons-and-objects-using-matplotlib) – Georgy Apr 06 '21 at 08:30
  • Interestingly enough, the code in the question is the exact copy of the code from the duplicate question. – Georgy Apr 06 '21 at 08:32

1 Answers1

1

Matplotlib cannot understand Polygon, you need to pass the polygon vertices in matplotlib plot.

Below code works:

from shapely.geometry import Polygon
import matplotlib.pyplot as plt

polygon1 = Polygon([(0,5),
                    (1,1),
                    (3,0)])

x,y = polygon1.exterior.xy
plt.plot(x,y)
nimrobotics
  • 114
  • 1
  • 8