在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执行会失效。
参考 https://stackoverflow.com/questions/64084923/easiest-way-to-install-a-gui-backend-for-matplotlib