且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法移动Matplotlib绘图窗口并使用红色X按钮退出

更新时间:2023-02-20 14:26:20

我偶然发现了一个类似的问题。这是因为你的matplotlib图和你的PyQt GUI都在同一个主线程中运行。因为他们在主线程,只有其中一个有自己的CPU。

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.

我试图解决这个问题,通过放置PyQT GUI或matplotlib内另一个线程。但这不工作。 PyQT和matplotlib都需要在主线程中运行。

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.

这里是一个解决方法。您可以从新创建的python shell启动matplotlib图:

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)



现在你的PyQT GUI和你绘制的matplotlib图有自己的Python解释器shell。

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.