等轴比演示

如何设置和调整具有等轴比的图像。

等轴比示例图

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. # Plot circle of radius 3.
  4. an = np.linspace(0, 2 * np.pi, 100)
  5. fig, axs = plt.subplots(2, 2)
  6. axs[0, 0].plot(3 * np.cos(an), 3 * np.sin(an))
  7. axs[0, 0].set_title('not equal, looks like ellipse', fontsize=10)
  8. axs[0, 1].plot(3 * np.cos(an), 3 * np.sin(an))
  9. axs[0, 1].axis('equal')
  10. axs[0, 1].set_title('equal, looks like circle', fontsize=10)
  11. axs[1, 0].plot(3 * np.cos(an), 3 * np.sin(an))
  12. axs[1, 0].axis('equal')
  13. axs[1, 0].axis([-3, 3, -3, 3])
  14. axs[1, 0].set_title('still a circle, even after changing limits', fontsize=10)
  15. axs[1, 1].plot(3 * np.cos(an), 3 * np.sin(an))
  16. axs[1, 1].set_aspect('equal', 'box')
  17. axs[1, 1].set_title('still a circle, auto-adjusted data limits', fontsize=10)
  18. fig.tight_layout()
  19. plt.show()

下载这个示例