我确信这是一个基本问题,但我找不到解决方案。我正在绘制一些椭圆,并想添加一个图例(例如第一个椭圆的颜色:数据1,...) 目前我设法绘制了一些椭圆,但我不知道如何绘制图例。
我的代码:
from pylab import figure, show, rand
from matplotlib.patches import Ellipse
NUM = 3
ells = [Ellipse(xy=rand(2)*10, width=rand(), height=rand(), angle=rand()*360)
for i in range(NUM)]
fig = figure()
ax = fig.add_subplot(111, aspect='equal')
for e in ells:
ax.add_artist(e)
e.set_clip_box(ax.bbox)
e.set_alpha(rand())
e.set_facecolor(rand(3))
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
show()
Run Code Online (Sandbox Code Playgroud)