I'm not too used to matplotlib dynamic plots, and thus I have some difficulties to create a desired plot. I'm trying to plot N timelines (not too much, less say less than 5) of the same large size (800k points). I would like to use a slider to represent this.
import numpy as np from matplotlib import pyplot as plt from matplotlib.widgets import Slider plt.ioff() timelines = [np.random.randint(-2, 5, size = 800000), np.random.randint(-2, 5, size = 800000), np.random.randint(-2, 5, size = 800000)] timelines_labels = ["label1", "label2", "label3"] def slide_plot(timelines, timelines_labels): f, ax = plt.subplots(len(timelines), 1, sharex = True, figsize = (20, 10)) def update(pos, ax = ax, timelines = timelines): for k, a in enumerate(ax): a.axis([pos,pos+80,-max(timelines[k])-1, max(timelines[k])+1]) f.canvas.draw_idle() f.subplots_adjust(bottom=0.25) plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False) t = np.arange(0.0, len(timelines[0]), 1) for k, a in enumerate(ax): a.plot(t, timelines[k], lw = 0.55, label=timelines_labels[k]) a.legend(loc="upper right") a.axis([0, 160000, -max(timelines[k])-1, max(timelines[k])+1]) ax[-1].set_xticks(np.arange(0.0, len(timelines[0])+80000, 80000)) axpos = plt.axes([0.2, 0.1, 0.65, 0.03]) spos = Slider(axpos, 'Time (ms)', valmin =0, valmax=800000, valinit=0) spos.on_changed(update) plt.show() slide_plot(timelines, timelines_labels) As you see, since my plots are sharing the X-axis, I'm taking out the xticks labels (will do the same with the xticks later) from all the axis except the bottom one.
Then I create the variable t which is just the time, I feel like it is useless, and ax[k].plot(timelines[k]) would be enough.
I do some more formatting by setting one tick every 80000 points.
And finally, I got the slider. Obviously, the update function does not work. I do not know the correct syntax, nor the right way to achieve this.
Thanks :)
EDIT: By placing the argument ax = ax and timelines = timelines it seems to start working, however I do not like the look of the function. I'm quite sure a better way exist.
EDIT: Latest script... And the output:

slide_plotdef update(pos):and remove the linepos = spos.valif you want. However the code as it currently is would already work. Hence the question where and how are you running this?axcolorslines are taken out. I'm using spyder, I've first set%matplotlibin the Ipytohn Constrole to open a new windows with the plots. The exammple in the post works, however, we my scenario, the scrolling bar doesn't work.