初学者使用python,我有一个散点图(http://i.stack.imgur.com/sQNHM.png)。我要做的是生成一个3D图,显示这些点的Z方向上的尖峰,其他地方都是0。在
这是我当前使用的代码:
plt.scatter(X, Y)
plt.show()
X, Y = np.meshgrid(X, Y)
Z = [1] * len(X)
fig = plt.figure()
ax = fig.add_subplot(1,1,1, projection='3d')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.plot_surface(X, Y, Z)
plt.show()
这给了我一个奇怪的结果(http://i.stack.imgur.com/7fLeT.png),我不知道该怎么做才能修复它。在
您可能不想使用二维绘图中的x和y值作为meshgrid的输入,因为您希望为您范围内x和y的所有整数值定义此绘图。如果我正确理解你的问题,原始的x和y应该定义尖峰的位置。以下是一种在指定位置获得高度为100的3D绘图的方法:
相关问题 更多 >
编程相关推荐