如何使用 Matplotlib 绘制 Shapely 多边形和对象?

matplotlibserver side programmingprogramming

要使用 matplotlib 绘制 Shapely 多边形和对象,步骤如下 −

  • 使用 (x, y) 数据点创建多边形对象。

  • 使用 polygon.exterior.xy 获取 x 和 y、外部数据和数组。

  • 使用 plot()  方法绘制 x 和 y 数据点,颜色为红色。

示例

from shapely.geometry import Polygon
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
polygon1 = Polygon([(0, 5),
   (1, 1),
   (3, 0),
   (4, 6),
])
x, y = polygon1.exterior.xy
plt.plot(x, y, c="red")
plt.show()

输出


相关文章