# importing the necessary libraries
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
# generating random dataset
x = [[i for j in range(0,5)] for i in range(0,5)] #生成测试数据,可以从excel中读取
y = [[j for j in range(0,5)] for i in range(0,5)]
z = [list(np.random.randint(80, size =(5))) for i in range(0,5)] #type = <class 'list'>
z = np.array(z) #type = <class 'numpy.ndarray'> #这里转一下, plot_surface 函数才能正确识别
fig1 = plt.figure(figsize=(9,8))
ax1 = fig1.add_subplot( projection='3d')
surf1 = ax1.plot_surface(x,y,z,cmap=plt.cm.viridis_r)
ax1.set_xlabel('X')
ax1.set_ylabel('Y')
ax1.set_zlabel('Z')
ax1.set_xticks(range(0,10))
ax1.set_yticks(range(0,10))
ax1.set_title('Original graph',fontsize=15)
fig1.colorbar(surf1,shrink=0.5)
fig1.tight_layout()
plt.show()
01-18
2万+
08-18
884
05-31
05-31
09-09
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交