当前位置: 代码迷 >> 综合 >> python3.6 matplotlib无法正常显示图片(Agg问题)
  详细解决方案

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

热度:80   发布时间:2023-10-26 00:11:21.0

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

  相关解决方案