先上图
代码段
import matplotlib.pyplot as plt
import numpy as np
import random
fig = plt.figure()
#比二维图多一个“pro”
#位置参数也能加
ax = fig.add_subplot(3,2,1,projection="3d")
ax2 = fig.add_subplot(3,2,2,projection="3d")
#绘制直线
#利用numpy生成一等差数列
t = np.linspace(-10,10)
z = 2*t
x = t
y = t
ax.plot(x,y,z,label="line plots")
ax.legend()
#绘制点scatter方法
x,y,z = [random.random() for i in range(10)],\
[random.random() for i in range(10)],\
[random.random() for i in range(10)]
ax2.scatter(x,y,z,s=5,c="r")
plt.show()