用python绘制填充多边形

2024-05-16 01:34:08 发布

您现在位置:Python中文网/ 问答频道 /正文

对于要绘制的多边形的面(Nx3)和顶点(Mx3),我有两个矩阵TriV。有没有matplotlib(或者其他的)方法可以做到这一点?类似于Matlab命令的东西

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

Tags: 方法命令matplotlib绘制矩阵多边形tripatch
1条回答
网友
1楼 · 发布于 2024-05-16 01:34:08

我不太清楚matlab是做什么的,但是可以使用^{}绘制多边形。改编自文档中的example

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()

enter image description here

相关问题 更多 >