【问题标题】:How do I plot a polygon from a list of tuples using Shapely package如何使用 Shapely 包从元组列表中绘制多边形
【发布时间】:2021-04-06 03:24:48
【问题描述】:

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

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'。

【问题讨论】:

标签: python matplotlib shapely


【解决方案1】:

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)

【讨论】:

  • 另外,考虑复制粘贴错误而不是添加屏幕截图。
  • 成功了。我现在明白了。 plot 函数需要 (x,y) 参数
猜你喜欢
  • 2019-08-26
  • 1970-01-01
  • 2023-02-17
  • 2022-11-30
  • 2022-01-25
  • 1970-01-01
  • 2020-04-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多