当前位置:   article > 正文

AttributeError: module ‘backend_interagg‘ has no attribute ‘FigureCanvas‘ 的解决办法_attributeerror: module 'backend_interagg' has no a

attributeerror: module 'backend_interagg' has no attribute 'figurecanvas
背景

我是在 PyCharm 中练习 matplotlib 出现这个问题的

原因

首先要知道 matplotlib 的 backend 使用的是默认配置 agg (agg不能显示绘制的图),要想显示绘制的图需要更改 agg 为 TkAgg

解决办法示例

来看一下已修改出来的代码

import cv2 as cv
# 下面这两行(真的是两行,这个“两”不是量词)代码就是要修改的地方
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt


# 读取图像
img = cv.imread('img/tt.png')
# 在matplotlib中展示图像
plt.imshow(img[:, :, ::-1])  # BGR ---> RGB
plt.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

首先,导包:import matplotlib
然后,修改 backend 配置:matplotlib.use('TkAgg')
这样就修改好了

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/371851
推荐阅读
相关标签
  

闽ICP备14008679号