Can't move matplotlib plot window and exit using red X button

I run Python v3.5

and matplotlib v1.4.3

on Windows 10 Home

. Until recently, I was writing a python script using matplotlib

a PyQt

GUI. The code " plt.show()

" will be written in another module instead of __main__

. When I run this code, there is Matplotlib figure

no way to move and exit with the red X button at the top of the right side of the picture. Strangely, the diagram is shown and it works really well.

Matplotlib Plot

Why is this symptom happening? and how can I revise it?

+1


source to share


1 answer


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

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

So here's a workaround. You can run a 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 drawing you are drawing have their own python interpreter wrapper. And they can run smoothly without blocking each other.

If you have further questions, do not hesitate to ask. I would be glad to help you.

0


source







All Articles