①导入matplotlib模块
import matplotlib
当我们并不想在页面中展示所作的图形,以减少内存时,有以下几种方法:
1)matplotlib.use(‘Agg’)
单用这一行代码,不会报错但会有提示
所以我们要另外再加上一行代码。汇总如下:
import matplotlib as mpl
mpl.use(‘Agg’)
mpl.rc(‘figure’, max_open_warning=0)
2)当然还有另外的一种方法。
import matplotlib.pyplot as plt
plt.ioff()
参考网址:https://matplotlib.org/faq/usage_faq.html#non-interactive-example