<div dir="ltr">Hello,<div><br></div><div>I have a problem with the way the legend labels are handled, certainly due to my poor knowledge of matplotlib internals.</div><div><br></div><div>Here an example (matplotlib-1.4.3, py-2.7):</div><div><br></div><div><div>In [1]: import matplotlib.pyplot as plt</div><div><br></div><div>In [2]: plt.plot([1,2,3], label='A')</div><div>Out[2]: [<matplotlib.lines.Line2D at 0x7f60749be310>]</div><div><br></div><div>In [3]: plt.plot([2,3,4], label='B')</div><div>Out[3]: [<matplotlib.lines.Line2D at 0x7f60749f1850>]</div><div><br></div><div>In [4]: ax = plt.gca()</div></div><div><br></div><div><div>In [5]: l = ax.get_legend_handles_labels()</div><div><br></div><div>In [6]: l</div><div>Out[6]:</div><div>([<matplotlib.lines.Line2D at 0x7f60749be310>,</div><div>  <matplotlib.lines.Line2D at 0x7f60749f1850>],</div><div> [u'A', u'B'])</div><div><br></div><div>In [7]: plt.legend(['C', 'D'])  ### This correctly modifies the legend to show 'C' and 'D', but then ...</div><div>Out[7]: <matplotlib.legend.Legend at 0x7f6081dce190></div><div><br></div></div><div>In [10]: l = ax.get_legend_handles_labels()<br></div><div><div><br></div><div>In [11]: l</div><div>Out[11]:</div><div>([<matplotlib.lines.Line2D at 0x7f60749be310>,</div><div>  <matplotlib.lines.Line2D at 0x7f60749f1850>],</div><div> [u'A', u'B'])</div></div><div><br></div><div>At this point I have no idea how to retrieve the list of shown labels, i.e. ['C', 'D'].</div><div>What am I missing? What other method should I use?</div><div><br></div><div>Thanks in advance</div></div>