Matplotlib在3d空间中向上箭头点

时间:2015-01-26 16:03:25

标签: python matplotlib charts

我试图在3d子图中的Z轴上有一个箭头点。我能够毫无问题地获得平面方向,但是对飞机进行正交测量是很困难的。

到目前为止我的代码

from mpl_toolkits.mplot3d import axes3d
import mpl_toolkits.mplot3d.art3d as art3d
from matplotlib.patches import Arrow, PathPatch
import matplotlib.pyplot as pl
import numpy as np


fig = pl.figure()
ax= fig.add_subplot(1, 1, 1, projection='3d')

arrowfig = Arrow(0,0,1,0,width =0.5, color = 'red')
ax.add_patch(arrowfig)
art3d.pathpatch_2d_to_3d(arrowfig, z=0, zdir="z")
arrowfig = Arrow(0,0,0,1,width =0.5, color = 'blue')
ax.add_patch(arrowfig)
art3d.pathpatch_2d_to_3d(arrowfig, z=0, zdir="z")
arrowfig = Arrow(0,0,0,-1,width =0.5, color = 'purple')
ax.add_patch(arrowfig)
art3d.pathpatch_2d_to_3d(arrowfig, z=0, zdir="z")
arrowfig = Arrow(0,0,-1,0,width =0.5, color = 'green')
ax.add_patch(arrowfig)
art3d.pathpatch_2d_to_3d(arrowfig, z=0, zdir="z")

ax.set_xlim([0,1])
ax.set_ylim([0,1])
ax.set_zlim([0,1])

pl.show()

1 个答案:

答案 0 :(得分:1)

要使矢量指向x-y平面,请将zdir函数的pathpatch_2d_to_3d参数设置为"x""y"。它定义了与变换箭头所在平面垂直的轴。

art3d.pathpatch_2d_to_3d(arrowfig, z=0, zdir="x")