日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

使用Python matplotlib繪制3D多邊形!

系統(tǒng) 1908 0

?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 matplotlib繪制3D多邊形!_第1張圖片

?

?

?

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é)果如下:

使用Python matplotlib繪制3D多邊形!_第2張圖片

?

?

?

?

我想你差不多了。 這是你想要的嗎?

            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感興趣。

使用Python matplotlib繪制3D多邊形!_第3張圖片

?

?

?


更多文章、技術(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ì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 滨州市| 济南市| 延边| 湾仔区| 玉林市| 林芝县| 巴青县| 巴南区| 上蔡县| 葫芦岛市| 茌平县| 江达县| 密云县| 百色市| 奇台县| 乐平市| 潞西市| 梧州市| 唐海县| 宁远县| 肇州县| 崇阳县| 略阳县| 视频| 含山县| 黄石市| 镇坪县| 潮安县| 定结县| 互助| 淮安市| 石阡县| 敦煌市| 景洪市| 阳江市| 社旗县| 德惠市| 道孚县| 平原县| 新巴尔虎右旗| 宜丰县|