python - Improve performance of matplotlib for subset of data -


i have little pyqt4 application shows plots big data set (100k points x 14 channels). want show period of 128 points , click show next period.

my naive approach create figures , plot subset of data on each step in loop. leads loading time quite second , thought may task.

is there way improve performance? did miss matplotlib built-in functions plot subset of data? wouldn't mind longer loading time @ beginning of application, maybe plot , zoom in?

edit: provided simple running example

took 7.39s plot 8 samples on machine

import time

import matplotlib.pyplot plt import numpy np   plt.ion()  num_channels = 14 num_samples = 1024  data = np.random.rand(num_channels, num_samples)  figure = plt.figure()  start = 0 period = 128  axes = [] in range(num_channels):     axes.append(figure.add_subplot(num_channels, 1, i+1))  end = start+period x_values = [x x in range(start, end)]  begin = time.time() num_plot = 0 in range(0, num_samples, period):     num_plot += 1     end = start+period      i, ax in enumerate(axes):         ax.hold(false)         ax.plot(x_values, data[i][start:end], '-')         ax.set_ylabel(i)     start += period      figure.canvas.draw() print("took %.2fs plot %d samples" % (time.time()-begin, num_plot)) 

using @joe-kington answer here: how update plot in matplotlib improved performance decent value.

i change y-values of line object using set_ydata(). line object returned when calling ax.plot() called once.

edit: added running example: took 3.11s plot 8 samples on machine

import time  import matplotlib.pyplot plt import numpy np   plt.ion()  num_channels = 14 num_samples = 1024  data = np.random.rand(num_channels, num_samples)  figure = plt.figure()  start = 0 period = 128  axes = [] in range(num_channels):     axes.append(figure.add_subplot(num_channels, 1, i+1))  end = start+period x_values = [x x in range(start, end)]  lines = [] begin = time.time() num_plot = 1 # first plot i, ax in enumerate(axes):     ax.hold(false)      # save line object     line, = ax.plot(x_values, data[i][start:end], '-')     lines.append(line)      ax.set_xlim([start,end])     ax.set_ylabel(i)  start += period _ in range(period, num_samples, period):     num_plot += 1     end = start + period     i, line in enumerate(lines):         line.set_ydata(data[i][start:end])     start += period      figure.canvas.draw() print("took %.2fs plot %d samples" % (time.time()-begin, num_plot)) 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -