0

Hi I have this function that plot ten points in a graph and it is called every 30000 seconds. But I'm getting an error after a while it says Out of memory and the program close. Can anybody help me?

 def plot(self):
    if self.plot_frame is not None:
        self.plot_frame.destroy()

    self.plot_frame = tk.Frame(self, bg=self.bg)
    self.plot_frame.pack(fill="both", expand=True)

    simulation = Simulation
    self.fig = plt.Figure()
    simulation.ax = self.fig.add_subplot(111)
    simulation.ax.set_title("Damage Accumulation Curve")
    simulation.ax.set_xlabel("Load Case")
    simulation.ax.set_ylabel("Accumulative Fatigue Damage")

    x_axis = np.arange(0, len(Simulation.accumulated) )

    x = np.array(x_axis[-10:])
    y = np.array(Simulation.accumulated[-10:])
    x = x[-10:]
    y = y[-10:]
    plt.clf()
    simulation.ax.plot(x, y)
    self.canvas = FigureCanvasTkAgg(self.fig, master=self.plot_frame)
    self.canvas.get_tk_widget().pack(fill="both", expand=True)
    self.canvas.draw()
    self.graph_theta.set(Simulation.theta)
    self.graph_arcl.set(Simulation.arcl)
    self.after(30000, self.plot)
4
  • 1
    stackoverflow.com/questions/74870484/… Commented Mar 12, 2023 at 14:15
  • Reuse the Figure and FigureCanvasTkAgg instance. You need to call canvas.draw() after plotting with Matplotlib API. Commented Mar 13, 2023 at 3:23
  • @relent95 how can I reuse the Figure and FigureCanvasTkAgg? I tryied every thing but it doesn't work it doesn't plot anything Commented Mar 13, 2023 at 12:11
  • See this answer. Commented Mar 13, 2023 at 15:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.