1

I currently am trying to plot some data that is being generated realtime from a simulation, this portion of code is a simplified version of what i have right now. It works but it is incredibly slow. Are there any tricks or other methods to speed this up.

My simplified code:

import matplotlib.pyplot as plt
import numpy as np
import time
plt.ion()

class plotting_class():
    def __init__(self):
        self.x = []
        self.y = []
        self.fig, self.ax = plt.subplots()

    def plotting(self,i):
        # for i in range(20):
        self.x.append(i)
        self.y.append(5*i)
        self.ax.plot(self.x, self.y, 'b')
        self.fig.canvas.flush_events()

plot_obj = plotting_class()
for i in range(20):
    plot_obj.plotting(i)
    time.sleep(1) # just to see the additions to the plot

    if i ==1:
        plt.show()
nlin22
  • 11
  • 1

0 Answers0