I work on the recent 4.11 (06.24.2020) and Slicer closes right after I close the window from matplotlib.
For your convenience I use that piece of code in Python Interactor:
from matplotlib import pyplot as plt
fig, axs = plt.subplots(1)
plt.show()
and a window opens. Right after I close it, Slicer closes as well.
For static plots, you can use “Agg” backend. It still works well - see example here.
Using matplotlib for interactive plots in a GUI application is very unclear, so I would not recommend doing it. Instead I would recommend using VTK plots, as they are faster and they integrate much nicer into 3D Slicer GUI and it allows you to directly interact with data stored in the scene.
If for some reason you want to still try to use matplotlib for interactive rendering then one workaround is to show the plot using plt.show(block=False), hide the close button on the figure image somehow (to make sure users don’t accidentally push it) and use plt.close() to cleanly close the plot. You could also try other matplotlib rendering backends (such as qt4 or qt5).
The only interactive functionality I want for now to have is the zoom in and show the coordinates once the cursor hovers the points. Maybe later to be able to show and hide some graphs at the same figure. Thus, I don’t think that png photos would give me that functionality.
I am wondering why at a latest version was working fine (4.11 03.10.2020), Do you think it is related to Slicer or matplotlib?