Matplotlib 在 3d 中有向上的箭头 space
Matplotlib have arrow point upwards in 3d space
我想在 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()
要使矢量指向 x-y 平面,请将 pathpatch_2d_to_3d
函数的 zdir
参数设置为 "x"
或 "y"
。它定义垂直于变换箭头所在平面的轴。
art3d.pathpatch_2d_to_3d(arrowfig, z=0, zdir="x")
我想在 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()
要使矢量指向 x-y 平面,请将 pathpatch_2d_to_3d
函数的 zdir
参数设置为 "x"
或 "y"
。它定义垂直于变换箭头所在平面的轴。
art3d.pathpatch_2d_to_3d(arrowfig, z=0, zdir="x")