椭圆集合
绘制椭圆的集合。虽然使用 EllipseCollection 或PathCollection 同样可行,但使用EllipseCollection 可以实现更短的代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| 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, 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()
|

参考
此示例中显示了以下函数,方法,类和模块的使用:
1 2 3 4 5 6
| import matplotlib matplotlib.collections matplotlib.collections.EllipseCollection matplotlib.axes.Axes.add_collection matplotlib.axes.Axes.autoscale_view matplotlib.cm.ScalarMappable.set_array
|
下载这个示例