I got a data array looking like data = [[1, 2, 3], [4, 5, 6], [7, 9, 10]....] and x values x_values = np.arange(3).
I want to show the plot of one sub-array at a time and incorporate a slider in my graph whose value should represent the index of the corresponding sub-array. So when I change the slider from for example 1 to 2, it should change from plotting data[1] to plotting data[2] against my x values.
My code looks something like this:
#Initial plot
fig, ax = plt.subplots()
i = 0
plt.subplots_adjust(bottom = 0.15)
ax.plot(x_values, data[i])
#Update function
def update_wave(val):
i = int(sliderwave.val)
x_values = np.arange(3)
ax.cla()
ax.plot(x_values, data[i))
fig.canvas.draw_idle()
#Sliders
axwave = plt.axes([0.25, 0.05, 0.5, 0.03])
sliderwave = Slider(axwave, 'Event No.', 0, 100, valinit=0, valfmt='%1.0f')
update_wave(i)
sliderwave.on_changed(update_wave)
It does not work like that. I guess some things don't make sense. Would appreciate some help.
