python3.6 matplotlib无法正常显示图片(Agg问题)

0.环境

ubuntu16.04
python3.6

1.问题

”UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.” when plotting figure with pyplot on Pycharm”

 

2.分析

和agg有关,之前印象中用过,近期忘记了。直接查询agg与问题userwarning提示。

参考:“UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.” when plotting figure with pyplot on Pycharm

 

3.解决

代码中添加:

import matplotlib
matplotlib.use('TkAgg')

终端中运行安装python3-tk:

sudo apt-get -y install python3.6-tk

因为是3.6的python,所以必须安装python3.6版本的tkinter!!!

 

参考

1.“UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.” when plotting figure with pyplot on Pycharm

你可能感兴趣的:(ubuntu,python3.6,matplotlib)