【参考:matplotlib后端(backends)概述_mighty13的博客-CSDN博客】
问题
import matplotlib
matplotlib.pyplot.get_backend() # 正常应该输出 'module://ipykernel.pylab.backend_inline'
如果是agg就是非交互模式
解决办法
官网:
- 更改您的 matplotlibrc 文件https://matplotlib.org/stable/tutorials/introductory/customizing.html#customizing-with-matplotlibrc-files
import matplotlib
matplotlib.matplotlib_fname()
'C:\\Users\\hp\\AppData\\Roaming\\Python\\Python38\\site-packages\\matplotlib\\mpl-data\\matplotlibrc'
把matplotlib文件夹删除
重新安装pip Install matplotlib
重新启动jupyter或者pycharm
https://matplotlib.org/stable/tutorials/introductory/customizing.html
方法二
import matplotlib
matplotlib.use('TkAgg') # 指定
%matplotlib inline # jupyter魔术命令,将图表嵌入到notebook中,可以省掉plt.show()
# 再导入其他的画图包
import matplotlib.pyplot as plt
import seaborn as sns