[英]How to draw the union shape of rectangles in python
我正在使用Matplotlib和Python。 我想绘制一组矩形的并集。 矩形可以连接或断开。 我还希望为其他组分配不同的颜色,以便知道组之间没有重叠区域。 你有什么主意吗?
谢谢你的帮助。
我添加了更精确的代码,我试图为每组矩形制作一个集合并给它们相同的边缘颜色,但是如何只获得一个形状(矩形组的周长)?
import numpy as np
import matplotlib
from matplotlib.patches import Rectangle
from matplotlib.collections import PatchCollection
import matplotlib.pyplot as plt
fig=plt.figure()
ax=fig.add_subplot(111)
patches = []
ListCollections=[]
while Cd1:
while Cd2:
patches += Rectangle((x,y), 400, 200)
p = PatchCollection(patches, cmap=None)
p.set_edgecolor('red')
p.set_facecolor(None)
ListCollections.append(p)
patches =[]
for l in ListCollections:
ax.add_collection(p)
plt.show()
看看Shapely吧。 有一个明确的联合示例http://toblerity.github.com/shapely/manual.html#object.union 。
要绘制Shapely几何图形,您可能还需要使用https://pypi.python.org/pypi/descartes 。
最后,如果联盟必须使用matplotlib艺术家,我在前几天实现了路径的Cohen-Sutherland裁剪算法 - 我相信将一个多边形剪切到另一个多边形与采用它们的联合相同。 我很乐意分享代码,如果那是你决定要去的路线(但是当你有Shapely时为什么会这样!)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.