首页 > 解决方案 > 绘制 3D 图形时出现问题,错误无法重塑数组,无法将大小为 712 的数组重塑为形状 (712,3)

问题描述

我在绘制 3D 图表时遇到问题。我有由 713 行和 3 列组成的 csv 文件

data = np.genfromtxt("graph-data.csv", delimiter=",", names=["x", "y","z"])
x, y, z = zip(*data)
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.set_xlabel('CPU availability(%)')
ax.set_ylabel('Memory availability(%)')
ax.set_zlabel('Frame Drop Rate(%)')
ax.plot_surface(np.array(x).reshape(712,3), np.array(y).reshape(712,3), np.array(z).reshape(712,3), 
cmap='viridis', edgecolor='none')
#ax.plot_surface(x, y, z,cmap='viridis', edgecolor='none')
plt.show()

错误

 ax.plot_surface(np.array(x).reshape(712,3), np.array(y).reshape(712,3), np.array(z).reshape(712,3), cmap='viridis', edgecolor='none')
 ValueError: cannot reshape array of size 712 into shape (712,3)

标签: pythonnumpy3d

解决方案


推荐阅读