Description
Trying to generate a legend from the figure options panel (in the qt backend) when there is more than 2 plots on the graph raise a exception.
Problem comes from this part of the code inside matplotlib/backends/qt_editor/figureoptions.py for the figure_edit function:
if generate_legend:
draggable = None
ncol = None
if axes.legend_ is not None:
old_legend = axes.get_legend()
draggable = old_legend._draggable is not None
ncol = old_legend._ncol
new_legend = axes.legend(ncol=ncol)
if new_legend:
new_legend.draggable(draggable)
ncol is always set to None, except for cases of an already existing legend. Inside the axes.legend method, internally ncol is set to 1 if the number of handles (which is the list of artists (lines, patches) to be added to the legend) is less than 2. So setting ncol=None inside figure_edit works when the number of plots is less than 2, but not instead, since ncol is already set to None.
Steps to reproduce in interactive mode in ipython (pylab loaded) with qt backend:
>>> ax.subplot(111)
>>> x = arange(100)
>>> y = sin(x)
>>> ax.plot(x, y, label="1")
>>> ax.plot(x, y, label="2")
>>> ax.plot(x, y, label="3")
>>> ax.plot(x, y, label="4")
>>> ax.plot(x, y, label="5")
then select in the figure options panel to generate a legend, then apply.
I started to write a PR with an option in the panel, next to the legend generation for the number of columns, but thought that someone has surely a better idea than this...