def impose_legend_limit(limit=<NUM_LIT:30>, axes="<STR_LIT>", **kwargs):
if axes=="<STR_LIT>": axes = _pylab.gca()<EOL>_pylab.axes(axes)<EOL>for n in range(<NUM_LIT:0>,len(axes.lines)):<EOL><INDENT>if n >  limit-<NUM_LIT:1> and not n==len(axes.lines)-<NUM_LIT:1>: axes.lines[n].set_label("<STR_LIT>")<EOL>if n == limit-<NUM_LIT:1> and not n==len(axes.lines)-<NUM_LIT:1>: axes.lines[n].set_label("<STR_LIT>")<EOL><DEDENT>_pylab.legend(**kwargs)<EOL>
This will erase all but, say, 30 of the legend entries and remake the legend.
You'll probably have to move it back into your favorite position at this point.