12
對於我想繪製的多邊形的面(Nx3)和頂點(Mx3),我有兩個矩陣Tri
和V
。有沒有任何matplotlib(或任何其他)的方式來做到這一點?同樣的事情也到MATLAB命令在Python中繪製填充的多邊形
patch('faces',Tri,'vertices',V,'facecolor',
'flat','edgecolor','none','facealpha',1)
對於我想繪製的多邊形的面(Nx3)和頂點(Mx3),我有兩個矩陣Tri
和V
。有沒有任何matplotlib(或任何其他)的方式來做到這一點?同樣的事情也到MATLAB命令在Python中繪製填充的多邊形
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()
你可能想多邊形轉換爲三角形,然後用['plot_tri_surf'](http://matplotlib.org/mpl_toolkits/mplot3d/ tutorial.html#三面圖)。 – will 2014-11-14 17:57:14