首页 > 其他分享 >在pycharm中使用Matplotlib的pyplot时报错MatplotlibDeprecationWarning

在pycharm中使用Matplotlib的pyplot时报错MatplotlibDeprecationWarning

时间:2023-04-12 10:27:16浏览次数:50  
标签:MatplotlibDeprecationWarning pyplot py matplotlib Matplotlib File line packages

在使用飞浆平台,练习平台上的demo:实践:手写数字识别任务,出现了下面的错误,demo地址: https://www.paddlepaddle.org.cn/documentation/docs/zh/guides/beginner/quick_start_cn.html

报错如下:

E:\joshua\python\demo\main.py:40: MatplotlibDeprecationWarning: Support for FigureCanvases without a required_interactive_framework attribute was deprecated in Matplotlib 3.6 and will be removed two minor releases later.
  plt.imshow(img[0])
Traceback (most recent call last):
  File "E:\joshua\python\demo\main.py", line 40, in <module>
    plt.imshow(img[0])
  File "C:\Python310\lib\site-packages\matplotlib\pyplot.py", line 2668, in imshow
    __ret = gca().imshow(
  File "C:\Python310\lib\site-packages\matplotlib\pyplot.py", line 2282, in gca
    return gcf().gca()
  File "C:\Python310\lib\site-packages\matplotlib\pyplot.py", line 879, in gcf
    return figure()
  File "C:\Python310\lib\site-packages\matplotlib\_api\deprecation.py", line 454, in wrapper
    return func(*args, **kwargs)
  File "C:\Python310\lib\site-packages\matplotlib\pyplot.py", line 813, in figure
    manager = new_figure_manager(
  File "C:\Python310\lib\site-packages\matplotlib\pyplot.py", line 382, in new_figure_manager
    _warn_if_gui_out_of_main_thread()
  File "C:\Python310\lib\site-packages\matplotlib\pyplot.py", line 360, in _warn_if_gui_out_of_main_thread
    if _get_required_interactive_framework(_get_backend_mod()):
  File "C:\Python310\lib\site-packages\matplotlib\pyplot.py", line 208, in _get_backend_mod
    switch_backend(rcParams._get("backend"))
  File "C:\Python310\lib\site-packages\matplotlib\pyplot.py", line 331, in switch_backend
    manager_pyplot_show = vars(manager_class).get("pyplot_show")
TypeError: vars() argument must have __dict__ attribute

Process finished with exit code 1

问题解决方式:

1.对pycharm编辑器进行设置

通过下面路径 File | Settings | Tools | Python Scientific

 

 

2.然后取消勾选show plots in tool window后,点击apply按钮,再点击ok按钮。

3.代码结尾加上 plt.show()后,代码就可以正常执行且不报错(注:这里的plt是我引用的别名,import matplotlib.pyplot as plt)

from matplotlib import pyplot as plt
plt.imshow(img[0])
plt.show()

 

   

标签:MatplotlibDeprecationWarning,pyplot,py,matplotlib,Matplotlib,File,line,packages
From: https://www.cnblogs.com/joshua317/p/17308862.html

相关文章

  • 解决matplotlib绘图时标签上中文无法正常显示的问题
    在使用matplotlib绘图过程中,有时我们会发现标签上中文无法正常显示出来,而是变成了一个个方框示例:解决方法:在图表代码行前加入一下代码plt.rcParams['font.sans-serif']='SimHei'解决后示例注意:需要把这行代码加入在使用matplotlib内置样式代码后,否则原有设置会被内置样......
  • python项目-数据可视化-matplotlib和plotly绘图
    matplotlib和plotly绘图参考书籍《Python编程从入门到实践》折线图15-1立方:数字的三次方被称为其立方。请绘制一个图形,显示前5个整数的立方值,再绘制一个图形,显示前5000个整数的立方值。15-2彩色立方:给你前面绘制的立方图指定颜色映射。importmatplotlib.pyplotasp......
  • python-matplotlib库
    学习过程中跟着敲的代码:importmatplotlib.pyplotaspltfrommatplotlib.imageimportimreadplt.rcParams["font.sans-serif"]=['ArialUnicodeMS']#设置字体#plt.rcParams["axes.unicode_minus"]=False#该语句解决图像中的“-”负号的乱码问题#x=np.arange(-n......
  • The Many Ways To Call Axes In Matplotlib
    %matplotlibwidgetfromIPython.displayimportdisplay,HTMLimportrefrompathlibimportPathimportcv2importnumpyasnpimportmatplotlib.pyplotaspltfrompprintimportpprintimportclipboardimportpandasaspdimportconcurrent.futuresimportt......
  • Python使用Matplotlib画以日期为X轴的图
    Python使用Matplotlib画以日期为X轴的图步骤:用pd把字符串格式的日期转成date格式.使用 AutoDateLocator 设置x轴的属性.1frommatplotlibimportpyplotasplt2importpandasaspd3frommatplotlib.datesimport(4MonthLocator,5AutoDateLoc......
  • 180122 特征值与特征向量的几何解释与python代码,附matplotlib绘制多边形
    HowtoPlotPolygonsinPythonShapely-ManualShapely-Test3Blue1Brown-线性代数的几何解释DownloadsShapely-WindowsShapely-MacorLinux红色基坐标(竖着看)1001绿色变换矩阵(竖着看)3102蓝色特征向量(竖着看)1−2√202√2黑色变换矩阵(左乘)特征向量(竖着......
  • Python 调用Matplotlib 读取txt、csv文件画图
    目录PythonMatplotlib读取txt、csv文件绘图使用方法PythonMatplotlib读取txt、csv文件绘图show_data.pyimportsysimportmatplotlib.pyplotaspltplt.rcParams['font.sans-serif']=['SimHei']#用来正常显示中文标签plt.rcParams['axes.unicode_minus']=False#用来......
  • 概率论与数理统计及其应用学习笔记1(numpy+matplotlib)
    先把基本概念都理一遍,博客的后半部分会上具体函数实现,没有前半部分的基础,后半部分看起来会有点吃力样本空间:某个实验的所有可能结果组成的集合样本点:样本空间的每个结......
  • pyinstaller 打包报错Failed to determine matplotlib‘s data directory
    #fromPyInstaller.utils.hooksimportexec_statement##mpl_data_dir=exec_statement(#"importmatplotlib;print(matplotlib.get_data_path())")#assert......
  • matplotlib时间线画图
    importmatplotlib.pyplotaspltimportnumpyasnpimportmatplotlib.datesasmdatesfromdatetimeimportdatetimeplt.rcParams['font.sans-serif']=['simhei']......