椭圆集合

绘制椭圆的集合。虽然使用 EllipseCollectionPathCollection 同样可行,但使用EllipseCollection 可以实现更短的代码。

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. from matplotlib.collections import EllipseCollection
  4. x = np.arange(10)
  5. y = np.arange(15)
  6. X, Y = np.meshgrid(x, y)
  7. XY = np.column_stack((X.ravel(), Y.ravel()))
  8. ww = X / 10.0
  9. hh = Y / 15.0
  10. aa = X * 9
  11. fig, ax = plt.subplots()
  12. ec = EllipseCollection(ww, hh, aa, units='x', offsets=XY,
  13. transOffset=ax.transData)
  14. ec.set_array((X + Y).ravel())
  15. ax.add_collection(ec)
  16. ax.autoscale_view()
  17. ax.set_xlabel('X')
  18. ax.set_ylabel('y')
  19. cbar = plt.colorbar(ec)
  20. cbar.set_label('X+Y')
  21. plt.show()

椭圆集合示例

参考

此示例中显示了以下函数,方法,类和模块的使用:

  1. import matplotlib
  2. matplotlib.collections
  3. matplotlib.collections.EllipseCollection
  4. matplotlib.axes.Axes.add_collection
  5. matplotlib.axes.Axes.autoscale_view
  6. matplotlib.cm.ScalarMappable.set_array

下载这个示例