I am writing a program where I have multiple figures that are plotting data from multiple sources in different forms (e.g. x vs. y, x/y vs. x, etc.). I am trying to introduce some element of interaction where the user can select certain points on one figure (whether they are from one series or multiple series) and for those selected points, the points are changed to a user-selected color on all figures. I've tried to implement pick events and the lasso selector to do the job, but I can't manage to interact with multiple figures, collections, and axes simultaneously. I've included some test code that I am using to just try to get this to work and as you will see, the interaction has some serious issues! Thanks for the help!
#plot picker
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
class SelectPoint(object):
def __init__(self, ax, collection, colorother='#ffffff'):
self.canvas = ax.figure.canvas
self.collection = collection
self.colorother = colorother
self.colorbyitem=colorbyitem
self.canvas.mpl_connect('pick_event', self.on_pick)
def on_pick(self, event):
self.thisparticle=event.artist
self.label=self.thisparticle.get_label()
self.index=event.ind[0]
print self.index
print self.colorbyitem[self.label][self.index]
self.colorbyitem[self.label][self.index]='#ff8000'
self.collection.set_color(self.colorbyitem[self.label])
self.collection.set_edgecolor('#000000')
self.canvas.draw_idle()
colors=['#0000ff','#0000ff','#0000ff','#0000ff','#0000ff']
colors1=['#00ffff','#00ffff','#00ffff','#00ffff','#00ffff']
x1=[1,2,3,4,5]
y1=[1,2,3,4,5]
x1=np.array(x1)
y1=np.array(y1)
colors=np.array(colors)
colors1=np.array(colors1)
colorbyitem={}
item='23532_10'
item2='23555_04'
colorbyitem[item]=colors
colorbyitem[item2]=colors1
x=[1,2,3,4,5]
y=[1,2,3,4,5]
x=np.array(x)
y=np.array(y)
subplot_kw = dict(xlim=(0, 5), ylim=(0, 5), autoscale_on=False)
fig5v4, ax=plt.subplots(subplot_kw=subplot_kw)
fig5v6, ax1=plt.subplots(subplot_kw=subplot_kw)
coll=ax.scatter(x,y, c=colors, s=75, picker=1, label=item)
coll1=ax1.scatter(x1, y1, c=colors, s=75, picker=1, label=item)
coll3=ax.scatter(1.1*y, .9*x, c=colors1, s=75, picker=1, label=item2)
coll4=ax1.scatter(1.1*y, .9*x, c=colors1, s=75, picker=1, label=item2)
selector=SelectPoint(ax, coll)
selector2=SelectPoint(ax1, coll1)
selector3=SelectPoint(ax, coll3)
selector4=SelectPoint(ax1, coll4)
plt.show()
raw_input()