备注
Go to the end 下载完整的示例代码.
椭圆集合#
绘制椭圆集合.虽然这同样可以使用 EllipseCollection 或 PathCollection ,但使用 EllipseCollection 可以使代码更短.
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.collections import EllipseCollection
x = np.arange(10)
y = np.arange(15)
X, Y = np.meshgrid(x, y)
XY = np.column_stack((X.ravel(), Y.ravel()))
ww = X / 10.0
hh = Y / 15.0
aa = X * 9
fig, ax = plt.subplots()
ec = EllipseCollection(ww, hh, aa, units='x', offsets=XY,
offset_transform=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()

参考
以下函数,方法,类和模块的用法在本例中显示:
matplotlib.collectionsmatplotlib.collections.EllipseCollectionmatplotlib.axes.Axes.add_collectionmatplotlib.axes.Axes.autoscale_viewmatplotlib.cm.ScalarMappable.set_array