我有一个以高度和纬度为维度的垂直数据集。我想把它画在一个像这样垂直的垒上。我的数据就像这个垂直表面
数据可以从我的git中获取https://github.com/kmmrao/3dplot_with_2d_surface.git
我通过组合以下方法找到了一个解决方案:
- https://matplotlib.org/stable/gallery/mplot3d/bars3d.html#sphx-glr-gallery-plot3d-bars3d-py
- 在matplotlib中绘制三维imshow((图像
将matplotlib.pyplot导入为plt将numpy导入为np
fig = plt.figure() ax = fig.add_subplot(projection='3d') yticks = [3, 2, 1, 0] X,Z = np.meshgrid(np.linspace(0,1,21), np.linspace(0,1,21)) data = np.cos(X) * np.cos(X) + np.sin(Z) * np.sin(Z) for c, k in zip(colors, yticks): Y = k*np.ones(X.shape) ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=plt.cm.BrBG(data/data.max()), shade=False) ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') ax.set_yticks(yticks) plt.show()