Skip to content
Advertisement

Drawing using matplotlib in pysimplegui

How can i clean up previous drawing before drawing again with matplotlib in PySimpleGui?

I wanted to draw a bar chart which i could be able to draw but not able to delete using the following code:

JavaScript

Are there any functions that i can call to clean up any previous drawings? Can someone please helpme with it, i was looking for it for really really long time in google, all i found are some related codes [1] that didn’t work well with me, i couldn’t find a simple and clean one. Thank you guys.

[1]https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_Matplotlib_Browser.py

Advertisement

Answer

I put your code into OpenAI’s Codex, and this is what I got back:

Code

JavaScript

Explanation of changes

  1. Added a global variable figure_canvas_agg to store the FigureCanvasTkAgg object.
  2. In the Draw event, check if the figure_canvas_agg is not None. If it is not None, call the clear method of the FigureCanvasTkAgg object.
  3. In the Delete event, check if the figure_canvas_agg is not None. If it is not None, call the clear method of the FigureCanvasTkAgg object.
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement