如何使用 Matplotlib 繪製 Shapely 多邊形和物件?


使用 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()

輸出

更新於: 06-May-2021

6K+ 瀏覽次數

開啟你的 事業

完成課程並獲得認證

開始
廣告