kojo justine
kojo justine

Reputation: 113

How do I plot a polygon from a list of tuples using Shapely package

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).

Upvotes: 0

Views: 3926

Answers (1)

nimrobotics
nimrobotics

Reputation: 124

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)

Upvotes: 1

Related Questions