用python绘制三棱锥(python3.6)

2025-10-27 04:43:06

1、加载模块:

import numpy as np

import mpl_toolkits.mplot3d  #3D绘图

import matplotlib.pyplot as plt #绘图

用python绘制三棱锥(python3.6)

2、创建一个三位坐标系:

ax=plt.subplot(111,projection='3d')

用python绘制三棱锥(python3.6)

3、绘制四个顶点:

x=[0,1,0,0]

y=[0,0,0,1]

z=[1,0,0,0]

for i in range(4):

    for j in range(4):

        ax.scatter((x[i]),(y[i]),(z[i]),color='g')

用python绘制三棱锥(python3.6)

4、图形如下。

用python绘制三棱锥(python3.6)

5、绘制棱:

……

        ax.plot((x[i],x[j]),(y[i],y[j]),(z[i],z[j]),color='b')

用python绘制三棱锥(python3.6)

6、给四个顶点加上标签:

……

    ax.text(x[i],y[i],z[i],i,color='blue')

用python绘制三棱锥(python3.6)

7、最后,给坐标轴加上标签:

ax.set_zlabel('z')

ax.set_ylabel('y')

ax.set_xlabel('x')

用python绘制三棱锥(python3.6)

8、下图是整体效果图。

用python绘制三棱锥(python3.6)

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢