我绘制了一组点并将该图嵌入到 Tkinter 画布中。我要做的是在单击一个/多个点时检索坐标。我能够使用以下代码(在嵌入到 Tkinter 之前)来做到这一点。但是,它仅适用于迭代中的第一个图。如何为接下来的 2 个地块扩展它?有人可以解释需要使用画布完成的更改吗?
outl=[]
index = []
list_rep = []
def on_pick(event):
thisline = event.artist
xdata, ydata = thisline.get_data()
tmp = []
index.append(i)
ind = event.ind
tmp.append(list(xdata[ind])[0])
tmp.append(list(ydata[ind])[0])
outl.append(tmp)
#print('on pick line:', zip(xdata[ind], ydata[ind]))
new_ydata1 = []
new_ydata2 = []
new_ydata3 = []
for i in range(3):
root = Tk.Tk()
root.wm_title("Embed in Tk")
ydata1 = np.array(Max_Correct_1[i])
ydata2 = np.array(Max_Correct_2[i])
ydata3 = np.array(Max_Correct_3[i])
Aveg=np.array(Avg[i])
f = Figure(figsize=(5,4), dpi=100)
ax1 = f.add_subplot(111)
ax1.axis([-9.5,-4.0,-10,105])
ax1.plot(Log_Values_Array,ydata1,'o',picker=7)
ax1.plot(Log_Values_Array,ydata2,'*',picker=7)
ax1.plot(Log_Values_Array,ydata3,'^',picker=7)
ax1.plot(Log_Values_Array,Aveg,'b--')
canvas = FigureCanvasTkAgg(f, master=root)
canvas.show()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
canvas.mpl_connect('pick_event',on_pick)
print outl
canvas.get_tk_widget().delete("all")
outl=[]
index = []
Tk.mainloop()