如何使用 Shapely 包从元组列表中绘制多边形

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

我试过了,但总是出错。 下面是我用来绘制的代码:

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


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

plt.plot(polygon1)
plt.show()

但是,我在调用 plt.plot(polygon1) 时总是收到 TypeError: float() argument must be a string or a number, not 'Polygon'

Matplotlib无法理解Polygon,需要在matplotlib中传递多边形顶点plot

以下代码有效:

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)