당신과 함께 전설 형식상의 축과 필터의 어린이를 얻을 수 있습니다 :
legends = [c for c in ax.get_children() if isinstance(c, mpl.legend.Legend)]
하지만 전혀 그 일을합니까? 내가 언급 한 것처럼 더 많은 범례를 추가하면 여러 개의 Legend
자식이 표시되지만 모두 동일한 개체를 가리키고 있습니다.
편집 :
축은 자체가 마지막 전설이 추가 유지, 그래서 당신은 .add_artist()
로 이전을 추가하는 경우, 여러 다른 전설 참조 : 예를 들어
:
fig, ax = plt.subplots()
l1, = ax.plot(x,y, 'k', label='l1')
leg1 = plt.legend([l1],['l1'])
l2, = ax.plot(x,y, 'k', label='l2')
leg2 = plt.legend([l2],['l2'])
ax.add_artist(leg1)
print(ax.get_children())
반환이를 개체 :
[<matplotlib.axis.XAxis at 0xd0e6eb8>,
<matplotlib.axis.YAxis at 0xd0ff7b8>,
<matplotlib.lines.Line2D at 0xd0f73c8>,
<matplotlib.lines.Line2D at 0xd5c1a58>,
<matplotlib.legend.Legend at 0xd5c1860>,
<matplotlib.legend.Legend at 0xd5c4b70>,
<matplotlib.text.Text at 0xd5b1dd8>,
<matplotlib.text.Text at 0xd5b1e10>,
<matplotlib.text.Text at 0xd5b1e48>,
<matplotlib.patches.Rectangle at 0xd5b1e80>,
<matplotlib.spines.Spine at 0xd0e6da0>,
<matplotlib.spines.Spine at 0xd0e6ba8>,
<matplotlib.spines.Spine at 0xd0e6208>,
<matplotlib.spines.Spine at 0xd0f10f0>]
이것이 당신이하고 싶은 일인지 여부!? 또한 축과 별도로 선 (또는 다른 유형)을 직접 저장할 수도 있습니다.
더 완벽한 예를 들려 줄 수 있습니까? 여기에 대해 당신이 무엇을 말하고 있는지 전혀 모르겠다. – tacaswell