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

如果编写程序类似于:

import matplotlib.pyplot as plt
plt.plot([1,2,3],[5,7,4])
plt.show()

或者:

import matplotlib
matplotlib.use('Agg')  # 使用Agg

import matplotlib.pyplot as plt
plt.plot([1,2,3],[5,7,4])
plt.show()

出现了  Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.这种错误

或许将引入的 Agg 改成TKAgg即可使用了,如果是第一种没有的话就加上这一句话:matplotlib.use('TkAgg')

import matplotlib
matplotlib.use('TkAgg')  # 大小写无所谓 tkaGg ,TkAgg 都行
import matplotlib.pyplot as plt

 

你可能感兴趣的:(python)