15 服务后端
16 非交互式环境中使用matplotlib
“RuntimeError: main thread is not in main loop”的错误。这个错误通常是由于尝试在多线程或非交互式环境中使用matplotlib的GUI引起的。
作Dash的画图后端
- 在代码开头添加以下语句,将matplotlib的后端设置为非交互式模式(例如Agg):
import matplotlib
'Agg') matplotlib.use(
- 在脚本执行完之后,添加以下代码进行清除:
'all') plt.close(