导入矩阵as mpl
from mpl _ toolkits.MP lot3dimportaxes 3d
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import酷炫棒棒糖/pfrommpl _ toolkits.MP lot3dimportproj 3d
classarrow3d(Fancyarrowpatch ) :
def__init_(self、xs、ys、zs、*args、**kwargs ) :
self._verts3d=xs,ys,zs
def draw (自,渲染器) :
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] )
def cuboid _ data (中心,size ) :
# supposeaxisdirection 3360 x : to left; y: to inside; z: to upper
# getthe (左、右、底)点
# get the length,width,and height
l,w,h=size
x=NP.Array([o[0],o[0] l,o[0] l,o[0],o[0],# xcoordinateofpointsinbottomsurface ) ) )
[o[0],o[0] l,o[0] l,o[0],o[0],# xcoordinateofpointsinuppersurface
[o[0],o[0] l,o[0] l,o[0],o[0],# xcoordinateofpointsinoutsidesurface
[o[0],o[0] l,o[0] l,o[0],o[0]] ) xcoordinateofpointsininsidesurface
y=NP.Array([o[1],o[1],o[1] w,o[1],# ycoordinateofpointsinbottomsurface ) ) )
[o[1],o[1],o[1] w,o[1] w,o[1],# ycoordinateofpointsinuppersurface ]
[o[1],o[1],o[1],o[1],o[1],# ycoordinateofpointsinoutsidesurface ]
[o[1] w,o[1] w,o[1] w,o[1] w,o[1]w] ) # ycoordinateofpointsininsidesurface
z=NP.Array([o[2],o[2],o[2],o[2],# zcoordinateofpointsinbottomsurface ) )。
[o[2] h,o[2] h,o[2] h,o[2] h,o[2] h],# zcoordinateofpointsinuppersurface
[o[2],o[2],o[2] h,o[2] h,o[2],# zcoordinateofpointsinoutsidesurface
[o[2]、o[2]、o[2] h、o[2] h、o[2]] ) # zcoordinateofpointsininsidesurface
返回x,y,z
if __name__=='__main__':
center=[ 0,0,0 ]
长度=1
宽度=1
height=1
fig=plt.figure (
ax1=fig.add_subplot(111,projection='3d ' )
x,y,z=cuboid_data(center,),width,height ) )
ax1.plot_surface(x,y,z,color='b ',rstride=1,cstride=1,alpha=0.1 ) )。
ax1.set_xlabel('x ' ) )。
ax1.set _ xlim (-1,1 ) )。
ax1.set_ylabel('y ) ) )。
ax1.set _ ylim (-1,1 ) )。
ax1.set_zlabel('z ) ) ) ) )。
ax1.set _ zlim (-1,1 ) )。
# Here we create the arrows:
arrow _ prop _ dict=dict (mutation _ scale=20,arrowstyle='-',shrinkA=0,shrinkB=0) ) ) ) )。
a=arrow 3d ([ 0,1 ]、[ 0,0 ]、[ 0,0 ]、**arrow_prop_dict,color='r ' ) () ) ) ) ) )
是ax1.add_Artist(a )
a=arrow 3d ([ 0,0 ]、[ 0,1 ]、[ 0,0 ]、**arrow_prop_dict,color='b ' ) () ) ) ) ) ) )。
是ax1.add_Artist(a )
a=arrow 3d ([ 0,0 ]、[ 0,0 ]、[ 0,1 ]、**arrow_prop_dict,color='g ' ) ) ) ) ) ) ) )。
是ax1.add_Artist(a )
# Give them a name:
ax1.text (0.0,0.0,-0.1,r'$0hsdhb/pax1.text ) 1.1,0,r'$xhsdHB/pax1.text ) 0,1.1,0,r'$yyt
我希望对你有帮助。 我也需要漂亮的箭头,如果你找到更好的请投稿; )