I have the following class which I intend to use in labelling specific parts of a time series.
class Labeler(object):
def __init__(self, accel_data, vline=0):
self.fig = plt.figure(figsize=(10,2))
self.accel_data = accel_data
x_ = np.arange(len(self.accel_data))
self.plot, = plt.plot(x_, self.accel_data, picker=100)
plt.xlim(0, len(self.accel_data)-1)
self.final_loc = 0
self.vline_loc = 0
self.vline = plt.axvline(self.vline_loc, color='red')
self.fig.canvas.mpl_connect('button_press_event', self._onclick)
self.button_next = Button(plt.axes([0.85, 0.78, 0.05, 0.1]), 'Next', color='#32CD32')
self.button_next.on_clicked(self._nextbutton)
self.button_done = Button(plt.axes([0.85, 0.65, 0.05, 0.1]), 'Done', color='orange')
self.button_done.on_clicked(self._donebutton)
plt.show(block=True)
self.starts = []
def _onclick(self, event):
self.final_loc = self.vline_loc
self.vline_loc = int(event.xdata)
self.vline.set_xdata(self.vline_loc)
def _nextbutton(self, event):
self.starts.append(['code', self.final_loc])
n = np.random.randint(1000)
self.plot.set_xdata(np.arange(n))
self.plot.set_ydata(np.random.rand(n))
self.plot.set_title(str(n))
def _donebutton(self, event):
plt.close() # close to stop plot
Now, I want to use this in an ipython notebook so that I can use it in a loop like this:
for i in range(5):
l = Labeler(np.random.rand(1000))
print(l.starts) # print the locs of vertical lines
cont = input("Press any key to continue")
My problem is that when I loop over the plot, it waits until the loop is finished before displaying the plot. What I want it to do is open a single plot, determine parts using the red line, and then proceed to the next plot. Please let me know how this can be accomplished. Thanks!

