gpt4 book ai didi

python - 在 python 中绘制填充的多边形

转载 作者:太空狗 更新时间:2023-10-29 17:13:19 24 4
gpt4 key购买 nike

我有两个矩阵 TriV 用于我要绘制的多边形的面 (Nx3) 和顶点 (Mx3)。是否有任何 matplotlib(或任何替代)方法可以做到这一点?类似于Matlab命令的东西

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

最佳答案

我不太确定 matlab 的作用,但您可以使用 matplotlib.patches.Polygon 绘制多边形.改编自 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

关于python - 在 python 中绘制填充的多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26935701/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com