“UserWarning: which is a non-GUI backend, so cannot show the figure“的解决方案

74 阅读1分钟

在jupyter lab中运行flg.show()会出现non-GUI的错误。 最简单的处理方式就是用tkinter

安装tkinter

$ sudo apt-get install python-tk
$ sudo apt-get install python3-tk

修改脚本

import matplotlib
matplotlib.use('TkAgg', force=True)
import matplotlib.pyplot as plt

这样就可以正常运行了, 但是建议是换save方式,因为远程访问lab执行会失效。

参考

stackoverflow.com/questions/6…