python matplotlib: Plotting to GUI in non-main thread

Viewed 2690

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?

2 Answers

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.

Related