问题描述
Jupyter环境的默认后端
在Jupyter Notebook或Jupyter Lab环境中运行以下代码可知
import matplotlib
print(matplotlib.get_backend())
Jupyter环境的默认后端为:
module://ipykernel.pylab.backend_inline
切换后端时出现异常
本机原后端为qt5agg。
运行matplotlib.use('tkagg')后,抛出异常ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'qt5' is currently running。
问题解决
重启jupyter内核。
先使用matplotlib.use('tkagg')切换后端,然后再导入pyplot模块。
import matplotlib
matplotlib.use('tkagg')
import matplotlib.pyplot as plt
plt.plot(1)
plt.show()
359



被折叠的 条评论
为什么被折叠?



