0

I am relatively new to python / matplotlib and have to plot huge numpy arrays (more than 6 mio entries). The problem is that the 6 plots I have take more than 3 GB of RAM and take very long to load. I researched a bit and found out that I can speed matplotlib up by not loading the axes and title every time. So now the code looks like this but it's still quite slow.

Should I use another module instead of matplotlib? How could I speed up the process?

Thanks a lot in advance

    for key, typus in self.sensorObjects.items():
        fig, ax = plt.subplots()
        ax.set_title(key)
        ax.set_xlabel('t (ms)')
        ax.set_ylabel(self.sensorObjects[key][0].unit)
        for sensor in typus:
            data = sensor.physical_data
            ax.plot(data)
        fig.canvas.update()
  • What exactly are you trying to achieve here? Save several figures to disk? Create an animation? – ImportanceOfBeingErnest Oct 19 '18 at 21:31
  • Must you plot all 6 plots at the same time? maybe do each task separately. – chickity china chinese chicken Oct 19 '18 at 21:31
  • @ImportanceOfBeingErnest I want to have the Plots Open in several windows. – murcielagos Oct 19 '18 at 21:42
  • @davedwards My Project leader wants all plots to be readily available – murcielagos Oct 19 '18 at 21:44
  • There already exists a matlab version and it works fast there. So it should be possible :) – murcielagos Oct 19 '18 at 21:47
  • Yes course, i mean you could generate all the plots but just display them separately, saving ram for each plot, instead of all plots at the same time – chickity china chinese chicken Oct 19 '18 at 21:50
  • Consider the following: I have a monitor with 1920 pixels in width. Even when I maximize a plot window on screen and consider some 15% to 20% margins of the axes, I have a maximum of 1600 pixels at my disposal to view the plot. Hence, showing a line plot with more than 1600 data points, does not make sense for me. – ImportanceOfBeingErnest Oct 19 '18 at 21:57
  • @ImportanceOfBeingErnest yes there is a lot of unnecessary data. I could do some smoothing, but its for experimenting purposes and with Zoom More than 1600 Data Points make sense :) – murcielagos Oct 20 '18 at 06:23
  • @davedwards Do you have an idea how to have the plots readily available? – murcielagos Oct 20 '18 at 06:25
  • Yes I'm sure there are lots of options, depending on what your project leader requires of you, but the easiest may be to save the plots to files for immediate opening/viewing with [pyplot.savefig](https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.savefig), see this answer: [Save plot to image file instead of displaying it using Matplotlib](https://stackoverflow.com/a/9890599/1248974). Might that be a possibility? – chickity china chinese chicken Oct 20 '18 at 07:03
  • @davedwards a rather high resolution is needed to zoom in the data (it is too huge to see everything at a glance), so an image is not an option I think :( – murcielagos Oct 20 '18 at 09:03

0 Answers0