极坐标下的三维曲面

演示绘制在极坐标中定义的曲面。使用YlGnBu颜色映射的反转版本。还演示了使用乳胶数学模式编写轴标签。

示例由Armin Moser提供。

极坐标下的三维曲面示例

  1. # This import registers the 3D projection, but is otherwise unused.
  2. from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. fig = plt.figure()
  6. ax = fig.add_subplot(111, projection='3d')
  7. # Create the mesh in polar coordinates and compute corresponding Z.
  8. r = np.linspace(0, 1.25, 50)
  9. p = np.linspace(0, 2*np.pi, 50)
  10. R, P = np.meshgrid(r, p)
  11. Z = ((R**2 - 1)**2)
  12. # Express the mesh in the cartesian system.
  13. X, Y = R*np.cos(P), R*np.sin(P)
  14. # Plot the surface.
  15. ax.plot_surface(X, Y, Z, cmap=plt.cm.YlGnBu_r)
  16. # Tweak the limits and add latex math labels.
  17. ax.set_zlim(0, 1)
  18. ax.set_xlabel(r'$\phi_\mathrm{real}$')
  19. ax.set_ylabel(r'$\phi_\mathrm{im}$')
  20. ax.set_zlabel(r'$V(\phi)$')
  21. plt.show()

下载这个示例