【发布时间】:2013-03-14 14:46:31
【问题描述】:
我正在使用 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()
【问题讨论】:
-
我从未见过 Matplotlib 中的任何函数来计算并集。 Matplotlib 旨在可视化数据,而不是计算数据。计算并集的形状后,您可以使用 Polygon() 制作不规则形状(而不是 Rectangle())。
标签: python matplotlib