Cannot move Matplotlib plot window and exit it using red X button

后端 未结 1 1164
轮回少年
轮回少年 2021-01-21 15:32

I\'m running Python v3.5 and matplotlib v1.4.3 on Windows 10 Home. Up to recently, I write the python script using matplotlib

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-21 16:09

    I stumbled on a similar problem. This is because your matplotlib figure and your PyQt GUI are both running in the same main thread. Since they are in the main thread, only one of them has the CPU for itself.

    I have tried to solve the problem by putting either the PyQT GUI or the matplotlib inside another thread. But that doesn't work. Both PyQT and matplotlib need to run in the main thread.

    So here is a workaround. You can start the matplotlib figure from a newly created python shell:

    import subprocess
    ...
    
        # When you click the button in your PyQT GUI,
        # Create a new process:
        myMatProcess = subprocess.Popen(['python', 'myGraph.py'], shell=True)
    

    Now your PyQT GUI and the matplotlib figure you're drawing have their own python interpreter shell. And they can run smoothly without blocking each other.

    If you have any further questions, don't hesitate to ask. I'd be happy to help you out.

    0 讨论(0)
提交回复
热议问题