Skip to content Skip to sidebar Skip to footer

Reliably Show Matplotlib (0.99 To 1.3.1) Figures Without Blocking

Is there any way to show a pyplot figure in Python 2.65, Matplotlib 0.99, without locking everything else? I have a program with a Pmw GUI running on Python 2.75 with Matplotlib 1.

Solution 1:

It looks like you are looking for:

plt.show(block=False) 

or plt.ion:

plt.ion()
plt.show()
# update figure, calc stuff
plt.pause()

Not really sure if they are available in 0.99.

Solution 2:

elyase's answer sent me into the right direction:

import matplotlib
matplotlib.interactive(True)

This at the beginning of a script is what it takes to make sure that matplotlib will always and in all environments create plots in a way that allows scripts to continue running, while allowing the user to manipulate the figure and the code to keep drawing into it.

Matplotlib has two modes of operating: The interactive and the non-interactive, and my script going into the latter mode was the problem.

I have still no idea why this is the default behaviour in some cases and not in others (had believed it was one standard setting per matplotlib installation). Since other scripts are able to run without the above. and there must be something that my script inadvertently does to land in non-interactive mode, but the above code is what will override the setting, come what may; at least in all scenarios I've tried so far: python 2.75, matplotlib 1.3.1 using Spyder's regular and dedicated shells and system shells, and Py 2.65, matplotlib 0.99, using system shells and IDLE.

P.S.: This does not seem to help on Linux. I tried to run the same skript (Tkinter GUI that opens plots, is able to draw into existing plots) on SuSE 13.1 (current version of python 2.7 and all libraries) and no single plot window pops up until the GUI is closed, and then they all jump at me ... it seems that it's not trivial to make matplotlib behave the same everywhere.

Post a Comment for "Reliably Show Matplotlib (0.99 To 1.3.1) Figures Without Blocking"