2
我正在使用Matplotlib和Python。我想绘制一组矩形的联合。 矩形可以连接或断开。我还希望为与其他组共享的边赋予不同的颜色,以知道组之间不存在重叠区域。你有什么主意吗?如何在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()
我从来没有在Matplotlib中看到任何函数来计算联合。 Matplotlib旨在可视化数据,而不是计算它。计算组合的形状后,可以使用Polygon()制作不规则形状(而不是Rectangle())。 – Robbert 2013-03-14 15:27:35
请参阅http://stackoverflow.com/questions/1517192/whats-a-good-library-to-do-computational-geometry-like-cgal-in-a-garbage-coll – tacaswell 2013-03-14 18:22:51