前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >在pycharm中使用Matplotlib的pyplot时报错MatplotlibDeprecationWarning

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

作者头像
joshua317
发布2023-04-19 19:13:24
1.2K0
发布2023-04-19 19:13:24
举报
文章被收录于专栏:技术博文

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

报错如下:

代码语言:javascript
复制
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)

代码语言:javascript
复制
from matplotlib import pyplot as plt
plt.imshow(img[0])
plt.show()

本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/298

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-04-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档