Matplotlib ion() and subprocesses

前端 未结 2 1100
失恋的感觉
失恋的感觉 2020-12-19 06:05

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 nev

相关标签:
2条回答
  • 2020-12-19 06:39

    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.

    0 讨论(0)
  • 2020-12-19 06:57

    This is probably overkill, but since no one had any better solutions I went to the threading module and it worked. If anyone has a simpler way to do this, please let me know.

    import subprocess
    import threading
    from matplotlib import pyplot as mpl
    ...
    class Graph(threading.Thread):
       def __init__(self,X,Y,min_tilt, min_energy):
           self.X = X
           self.Y = Y
           self.min_tilt = min_tilt
           self.min_energy = min_energy
           threading.Thread.__init__(self)
    
       def run(self):
           X = self.X
           Y = self.Y
           dx = (X.max()-X.min())/30.0
           x = np.arange(X.min(),X.max()+dx,dx)
           y = quad(x,fit)
           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(self.min_tilt, self.min_energy, c='r')
           mpl.show()
    thread = Graph(X,Y,min_tilt,min_energy)
    thread.start()
    
    0 讨论(0)
提交回复
热议问题