垂直線をインタラクティブに移動して、プロットされたデータの二等分を視覚化しようとしていますが、調整された線を表示できないようです...
import Tkinter
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
class App:
def __init__(self, master, increment=.2, height=10):
self.increment = increment
# Create a container
frame = Tkinter.Frame(master)
# Make buttons...
self.button_left = Tkinter.Button(frame,text="< Move Left",
command=self.move_left)
self.button_left.pack(side="left")
self.button_right = Tkinter.Button(frame,text="Move Right >",
command=self.move_right)
self.button_right.pack(side="left")
fig = Figure()
ax = fig.add_subplot(111)
x = [3]*height
y = range(height)
#so that it's a tuple
self.line, = ax.plot(x, y)
self.canvas = FigureCanvasTkAgg(fig, master=master)
self.canvas.show()
self.canvas.get_tk_widget().pack(side='top', fill='both', expand=1)
frame.pack()
def move_left(self):
x, y = self.line.get_data()
self.line.set_xdata(x-self.increment)
x, y = self.line.get_data()
print "x: {0}".format(x)
print "y: {0}".format(y)
#self.canvas.draw()
self.canvas.blit()
def move_right(self):
x, y = self.line.get_data()
self.line.set_xdata(x+self.increment)
x, y = self.line.get_data()
print "x: {0}".format(x)
print "y: {0}".format(y)
#self.canvas.draw()
self.canvas.blit()
root = Tkinter.Tk()
app = App(root)
root.mainloop()
Joe Kingstonの回答hereを見てきましたが、最初に plot() に x 座標と y 座標の両方を指定すると、問題が発生するようです...