Frontpage 轮廓示例

此示例再现Frontpage 轮廓示例。

Frontpage 轮廓示例

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. from matplotlib import cm
  4. extent = (-3, 3, -3, 3)
  5. delta = 0.5
  6. x = np.arange(-3.0, 4.001, delta)
  7. y = np.arange(-4.0, 3.001, delta)
  8. X, Y = np.meshgrid(x, y)
  9. Z1 = np.exp(-X**2 - Y**2)
  10. Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
  11. Z = Z1 - Z2
  12. norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())
  13. fig, ax = plt.subplots()
  14. cset1 = ax.contourf(
  15. X, Y, Z, 40,
  16. norm=norm)
  17. ax.set_xlim(-2, 2)
  18. ax.set_ylim(-2, 2)
  19. ax.set_xticks([])
  20. ax.set_yticks([])
  21. fig.savefig("contour_frontpage.png", dpi=25) # results in 160x120 px image
  22. plt.show()

下载这个示例