Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib ion() and subprocesses

I am trying to have a plot pop up so the user can confirm that a fitting worked, but not hang up the entire process doing so. However, while the window appears, there is never anything in it, and it is "Not Responding". I suspect that there is a bad interaction with the subprocess functionality, as this code is front-ending and data processing for a simulation being run in C++.

import subprocess
import numpy as np
from matplotlib import pyplot as mpl
...
mpl.ion()
fig = mpl.figure()
ax = fig.add_subplot(1,1,1)
ax.grid(True)
ax.plot(x, y, 'g')
ax.scatter(X, Y, c='b')
ax.scatter(min_tilt, min_energy, c='r')
mpl.draw()
...
subprocess.call(prog)

The following subprocess does open. If I remove the ion() call and use mpl.show(), then the plot works fine, but the entire process holds up until the window is closed. I need the process to continue while the user looks at the graph. Is there a way to do this?

like image 902
Elliot Avatar asked Jul 14 '12 01:07

Elliot


1 Answers

Instead of the mpl.draw(), try:

mpl.pause(0.001)

when using the matplotlib interactive mode ion(). Note that this only works from matplotlib 1.1.1 RC or higher.

like image 65
Niels Avatar answered Sep 28 '22 05:09

Niels