I have to plot several data sets in one plot. It is useful to be able to highlight one or more of the plots in order to compare them. For this, I toggle the line style of th
Another approach similar to tcaswell's solution counting events. Only 3 lines added to the original legend picking example. It uses python's function attributes.
def onpick(event):
if onpick.count % 2 == 0: #### LINE ADDED ####
# on the pick event, find the orig line corresponding to the
# legend proxy line, and toggle the visibility
legline = event.artist
origline = lined[legline]
vis = not origline.get_visible()
origline.set_visible(vis)
# Change the alpha on the line in the legend so we can see what lines
# have been toggled
if vis:
legline.set_alpha(1.0)
else:
legline.set_alpha(0.2)
fig.canvas.draw()
onpick.count += 1 #### LINE ADDED ####
onpick.count = 0 #### LINE ADDED ####