如下所示:
from matplotlib import pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import axes3d
fig = plt.figure()
ax = axes3d(fig)
#列出实验数据
point=[[2,3,48],[4,5,50],[5,7,51],[8,9,55],[9,12,56]]
plt.xlabel("x1")
plt.ylabel("x2")
#表示矩阵中的值
isum = 0.0
x1sum = 0.0
x2sum = 0.0
x1_2sum = 0.0
x1x2sum = 0.0
x2_2sum = 0.0
ysum = 0.0
x1ysum = 0.0
x2ysum = 0.0
#在图中显示各点的位置
for i in range(0,len(point)):
x1i=point[i][0]
x2i=point[i][1]
yi=point[i][2]
ax.scatter(x1i, x2i, yi, color="red")
show_point = "["+ str(x1i) +","+ str(x2i)+","+str(yi) + "]"
ax.text(x1i,x2i,yi,show