简体   繁体   English

python matplotlib:在非主线程中绘制到 GUI

[英]python matplotlib: Plotting to GUI in non-main thread

I had some issues with matplotlib runing in a non-main thread..我在非主线程中运行 matplotlib 时遇到了一些问题。

I'm doing a GUI with tkinter that runs some operations in a new thread, showing a progress bar, etc.. then plot graphics.我正在使用 tkinter 做一个 GUI,它在新线程中运行一些操作,显示进度条等。然后是 plot 图形。

The problem is: the plot part just doesnt work and I that warning comes:问题是: plot 部分不起作用,我警告来了:

UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail.用户警告:在主线程之外启动 Matplotlib GUI 可能会失败。

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?也许如果我不能回调主线程,我可以在主线程中运行 matplotlib 部分,在代码的这个非主线程部分调用它的 function 吗?

All GUI function calls must happen from the main thread.所有 GUI function 调用必须从主线程发生。

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.有关线程间通信,请参阅https://docs.python.org/3/library/queue.html In short, you can Queue.put the result from the secondary thread and Queue.get the result in the main thread.简而言之,您可以 Queue.put 从辅助线程中获取结果,并在主线程中 Queue.get 中获取结果。

Matplotlib is not thread-safe , you could use Multiprocessing instead and have another process handle the graphics plotting. Matplotlib 不是线程安全的,您可以改用多处理并让另一个进程处理图形绘图。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在非主线程中创建GUI小部件 - How to create GUI widget in a non-main thread 在非主线程中显示对话框 - Showing dialog in non-main thread 如何在非主线程上运行 pyttsx3(文本到语音)? (Python)[已回答] - How to run pyttsx3 (text-to-speech) on non-main thread? (Python) [Answered] 无法使用非主线程在Python-OpenCV(cv2)中启动相机捕获 - Unable to start camera capture in Python-OpenCV (cv2) using a non-main thread asyncio是否支持从非主线程运行子进程? - Does asyncio support running a subprocess from a non-main thread? 主线程中对queue.join()的调用对非主线程有什么影响? - What does a call on queue.join() in main thread do to non-main threads? QApplication 在 pyQt4 的第二个进程的非主线程中:这段代码是否合法,如果不合法,为什么它有效? - QApplication in a non-main thread of second process with pyQt4: is this code legal, and if not, why does it work? TIS / TSM非主线程错误;热键触发的pygame脚本(臀部,pygame,键盘) - TIS/TSM non-main thread error; pygame script triggered by hotkey (rumps, pygame, keyboard) python收集多个函数的返回值,并在一个非主函数处针对所有函数验证输入 - python gathering return value of multiple function and validate input against all function at one non-main function 用户警告:在主线程之外启动 Matplotlib GUI 可能会失败 - UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM