第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在Matplotlib中繪制一個(gè)3d立方體,球體和矢量

在Matplotlib中繪制一個(gè)3d立方體,球體和矢量

幕布斯6054654 2019-09-20 15:37:53
我使用Matplotlib搜索如何用盡可能少的指令繪制內(nèi)容但我在文檔中找不到任何幫助。我想繪制以下內(nèi)容:線框立方體,以0為中心,邊長為2“線框”球體,以0為中心,半徑為1坐標(biāo)[0,0,0]處的一個(gè)點(diǎn)從這一點(diǎn)開始并轉(zhuǎn)到[1,1,1]的向量怎么做?
查看完整描述

2 回答

?
慕娘9325324

TA貢獻(xiàn)1783條經(jīng)驗(yàn) 獲得超4個(gè)贊

它有點(diǎn)復(fù)雜,但您可以通過以下代碼繪制所有對(duì)象:


from mpl_toolkits.mplot3d import Axes3D

import matplotlib.pyplot as plt

import numpy as np

from itertools import product, combinations



fig = plt.figure()

ax = fig.gca(projection='3d')

ax.set_aspect("equal")


# draw cube

r = [-1, 1]

for s, e in combinations(np.array(list(product(r, r, r))), 2):

    if np.sum(np.abs(s-e)) == r[1]-r[0]:

        ax.plot3D(*zip(s, e), color="b")


# draw sphere

u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]

x = np.cos(u)*np.sin(v)

y = np.sin(u)*np.sin(v)

z = np.cos(v)

ax.plot_wireframe(x, y, z, color="r")


# draw a point

ax.scatter([0], [0], [0], color="g", s=100)


# draw a vector

from matplotlib.patches import FancyArrowPatch

from mpl_toolkits.mplot3d import proj3d



class Arrow3D(FancyArrowPatch):


    def __init__(self, xs, ys, zs, *args, **kwargs):

        FancyArrowPatch.__init__(self, (0, 0), (0, 0), *args, **kwargs)

        self._verts3d = xs, ys, zs


    def draw(self, renderer):

        xs3d, ys3d, zs3d = self._verts3d

        xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)

        self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))

        FancyArrowPatch.draw(self, renderer)


a = Arrow3D([0, 1], [0, 1], [0, 1], mutation_scale=20,

            lw=1, arrowstyle="-|>", color="k")

ax.add_artist(a)

plt.show()

http://img1.sycdn.imooc.com//5d8481e900016e1a08000600.jpg

查看完整回答
反對(duì) 回復(fù) 2019-09-20
  • 2 回答
  • 0 關(guān)注
  • 2930 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)