簡體   English   中英

在python中繪制填充多邊形

[英]ploting filled polygons in python

我有兩個矩陣TriV用於要繪制的多邊形的面(Nx3)和頂點(Mx3)。 是否有任何 matplotlib(或任何替代)方法來做到這一點? 類似於 Matlab 命令的東西

patch('faces',Tri,'vertices',V,'facecolor', 
      'flat','edgecolor','none','facealpha',1)

我不確定 matlab 是做什么的,但您可以使用matplotlib.patches.Polygon繪制多邊形。 改編自文檔中的示例

import numpy as np

import matplotlib.pyplot as plt
import matplotlib
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection

fig, ax = plt.subplots()
patches = []
num_polygons = 5
num_sides = 5

for i in range(num_polygons):
    polygon = Polygon(np.random.rand(num_sides ,2), True)
    patches.append(polygon)

p = PatchCollection(patches, cmap=matplotlib.cm.jet, alpha=0.4)

colors = 100*np.random.rand(len(patches))
p.set_array(np.array(colors))

ax.add_collection(p)

plt.show()

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM