我曾经使用 shapely 制作一个圆圈并将其绘制在之前填充的图上。这曾经工作得很好。最近,我收到索引错误。我将代码分解为最简单的操作,但它甚至无法执行最简单的循环。
import descartes
import shapely.geometry as sg
import matplotlib.pyplot as plt
circle = sg.Point((0,0)).buffer(1)
# Plot the cricle
fig = plt.figure()
ax = fig.add_subplot(111)
patch = descartes.PolygonPatch(circle)
ax.add_patch(patch)
plt.show()
Run Code Online (Sandbox Code Playgroud)
以下是我现在遇到的错误。我觉得这可能是新版本与可能发生的事情不匹配。我尝试卸载并重新安装最后一个已知的稳定版本,但这也没有帮助
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Cell In[20], line 6
4 fig = plt.figure()
5 ax = fig.add_subplot(111)
----> 6 patch = descartes.PolygonPatch(circle)
7 ax.add_patch(patch)
8 plt.show()
File ~/env/lib/python3.8/site-packages/descartes/patch.py:87, in PolygonPatch(polygon, **kwargs)
73 def PolygonPatch(polygon, **kwargs):
74 """Constructs a matplotlib patch from a geometric object
75
76 …Run Code Online (Sandbox Code Playgroud)