【Matplotlib】Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure

错误:

使用Matplotlib时报错:Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.

解决方案:

加入use(‘TkAgg’)语句,例如:

import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.use(‘TkAgg’)

但是加入以后可能还是无法显示图片,原因在于mpl.use(‘TkAgg’)语句要在导入所有包之后即最后加。