【已解决】“Matplotlib is currently using agg, which is a non-GUI backend”

python程序无法运行出图形化界面

完整报错信息:
“UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.”

以下是引用的模块,检查是否安装好已引用的模块:

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d

模块安装没有问题,使用查看图像的方法是plt.show()
根据报的错,agg存在问题,那我们就安装使用另外一个图形化PyQt5开发库

PS D:\MyPythonCode\Algorithm\EX07> pip install PyQt5
Defaulting to user installation because normal site-packages is not writeable
Collecting PyQt5
  Downloading PyQt5-5.15.9-cp37-abi3-win_amd64.whl (6.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.8/6.8 MB 4.6 MB/s eta 0:00:00
Collecting PyQt5-sip<13,>=12.11 (from PyQt5)
  Downloading PyQt5_sip-12.12.1-cp311-cp311-win_amd64.whl (78 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 78.4/78.4 kB 4.5 MB/s eta 0:00:00
Collecting PyQt5-Qt5>=5.15.2 (from PyQt5)
  Downloading PyQt5_Qt5-5.15.2-py3-none-win_amd64.whl (50.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 50.1/50.1 MB 6.2 MB/s eta 0:00:00
Installing collected packages: PyQt5-Qt5, PyQt5-sip, PyQt5
  WARNING: The scripts pylupdate5.exe, pyrcc5.exe and pyuic5.exe are installed in 'C:\Users\ch  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed PyQt5-5.15.9 PyQt5-Qt5-5.15.2 PyQt5-sip-12.12.1

安装成功后,重新运行程序,图形化界面成功显示:
在这里插入图片描述
PS:如果没有,请在前面导入以下包

import matplotlib
matplotlib.use('Qt5Agg')

猜你喜欢

转载自blog.csdn.net/HelloWorld_4396/article/details/131219464