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