椭圆集合
绘制椭圆的集合。虽然使用 EllipseCollection 或PathCollection 同样可行,但使用EllipseCollection 可以实现更短的代码。
import matplotlib.pyplot as pltimport numpy as npfrom matplotlib.collections import EllipseCollectionx = np.arange(10)y = np.arange(15)X, Y = np.meshgrid(x, y)XY = np.column_stack((X.ravel(), Y.ravel()))ww = X / 10.0hh = Y / 15.0aa = X * 9fig, ax = plt.subplots()ec = EllipseCollection(ww, hh, aa, units='x', offsets=XY,transOffset=ax.transData)ec.set_array((X + Y).ravel())ax.add_collection(ec)ax.autoscale_view()ax.set_xlabel('X')ax.set_ylabel('y')cbar = plt.colorbar(ec)cbar.set_label('X+Y')plt.show()

参考
此示例中显示了以下函数,方法,类和模块的使用:
import matplotlibmatplotlib.collectionsmatplotlib.collections.EllipseCollectionmatplotlib.axes.Axes.add_collectionmatplotlib.axes.Axes.autoscale_viewmatplotlib.cm.ScalarMappable.set_array
