2020年11月14日 星期六

Python3 Matplotlib plt.show() failed解法

在python下使用matplotlib時可能無法正常顯示圖表,並爆出以下錯誤訊息

UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. 


解法:

1. 安裝python3-tk

sudo apt-get install python3-tk


2. 解除安裝matplotlib再重新安裝

可先pip -V或pip3 -V,確認目前python3是使用pip or pip3來管理套件

pip uninstall matplotlib

pip install matplotlib


3. 完成,重新測試應可正常顯示圖表