?OS:Ubuntu 18.04 LTS
Python 3.6
我在瀏覽網(wǎng)頁(yè)時(shí)未能找到以下簡(jiǎn)單問(wèn)題的解決方案:
如何使用頂點(diǎn)值繪制3D多邊形(比如填充的矩形或三角形)? 我嘗試過(guò)很多想法,但都失敗了,請(qǐng)看:
from mpl_toolkits.mplot3d import Axes3D from matplotlib.collections import PolyCollection import matplotlib.pyplot as plt fig = plt.figure() ax = Axes3D(fig) x = [0,1,1,0] y = [0,0,1,1] z = [0,1,0,1] verts = [zip(x, y,z)] ax.add_collection3d(PolyCollection(verts),zs=z) plt.show()
上面的解決方案適用于Python 2,在使用python 3運(yùn)行時(shí)出現(xiàn)錯(cuò)誤TypeError: object of type 'zip' has no len()。
?
?
?
Python資源共享群:484031800
根據(jù)接受的答案更新:
import mpl_toolkits.mplot3d as a3 import matplotlib.colors as colors import pylab as pl import scipy as sp ax = a3.Axes3D(pl.figure()) for i in range(10000): vtx = sp.rand(3,3) tri = a3.art3d.Poly3DCollection([vtx]) tri.set_color(colors.rgb2hex(sp.rand(3))) tri.set_edgecolor('k') ax.add_collection3d(tri) pl.show()
結(jié)果如下:
?
?
?
?
我想你差不多了。 這是你想要的嗎?
from mpl_toolkits.mplot3d import Axes3D from mpl_toolkits.mplot3d.art3d import Poly3DCollection import matplotlib.pyplot as plt fig = plt.figure() ax = Axes3D(fig) x = [0,1,1,0] y = [0,0,1,1] z = [0,1,0,1] verts = [list(zip(x,y,z))] ax.add_collection3d(Poly3DCollection(verts)) plt.show()
您可能也對(duì)art3d.pathpatch_2d_to_3d感興趣。
?
?
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
