2

I had some issues with matplotlib runing in a non-main thread..

I'm doing a GUI with tkinter that runs some operations in a new thread, showing a progress bar, etc.. then plot graphics.

The problem is: the plot part just doesnt work and I that warning comes:

UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail.

There's a solution?

Maybe if I can't call main thread back, can I run the matplotlib part in the main thread calling it's function in this non-main thread part of the code?

1
  • Can you add a minimum working example of your code to your question? Commented Dec 11, 2020 at 7:58

2 Answers 2

4

All GUI function calls must happen from the main thread.

You may be able to compute graphics in another thread and communicate the results to the main thread to be displayed.

See https://docs.python.org/3/library/queue.html for inter-thread communication. In short, you can Queue.put the result from the secondary thread and Queue.get the result in the main thread.

Sign up to request clarification or add additional context in comments.

Comments

2

Matplotlib is not thread-safe, you could use Multiprocessing instead and have another process handle the graphics plotting.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.