将轮廓轮廓投影到图形上

演示显示3D表面,同时还将轮廓“轮廓”投影到图形的“墙壁”上。

有关填充版本,请参见contourf3d_demo2。

将轮廓轮廓投影到图形上

  1. from mpl_toolkits.mplot3d import axes3d
  2. import matplotlib.pyplot as plt
  3. from matplotlib import cm
  4. fig = plt.figure()
  5. ax = fig.gca(projection='3d')
  6. X, Y, Z = axes3d.get_test_data(0.05)
  7. # Plot the 3D surface
  8. ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
  9. # Plot projections of the contours for each dimension. By choosing offsets
  10. # that match the appropriate axes limits, the projected contours will sit on
  11. # the 'walls' of the graph
  12. cset = ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
  13. cset = ax.contour(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
  14. cset = ax.contour(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)
  15. ax.set_xlim(-40, 40)
  16. ax.set_ylim(-40, 40)
  17. ax.set_zlim(-100, 100)
  18. ax.set_xlabel('X')
  19. ax.set_ylabel('Y')
  20. ax.set_zlabel('Z')
  21. plt.show()

下载这个示例