如何使用 Matplotlib 绘制 Shapely 多边形和对象? [英] How do I plot Shapely polygons and objects using Matplotlib?
本文介绍了如何使用 Matplotlib 绘制 Shapely 多边形和对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的计算几何项目中使用Shapely.为此,我需要能够可视化和显示多边形、线条和其他几何对象.我尝试为此使用Matplotlib,但遇到了麻烦.
I want to use Shapely for my computational geometry project. I need to be able to visualize and display polygons, lines, and other geometric objects for this. I've tried to use Matplotlib for this but I am having trouble with it.
from shapely.geometry import Polygon
import matplotlib.pyplot as plt
polygon1 = Polygon([(0,5),
(1,1),
(3,0),
])
plt.plot(polygon1)
plt.show()
我希望能够在图中显示这个多边形.我将如何更改我的代码来做到这一点?
I would like to be able to display this polygon in a plot. How would I change my code to do this?
推荐答案
使用:
import matplotlib.pyplot as plt
x,y = polygon1.exterior.xy
plt.plot(x,y)
或者,更简洁:
plt.plot(*polygon1.exterior.xy)
这篇关于如何使用 Matplotlib 绘制 Shapely 多边形和对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文