ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

解决matplotlib报错: AttributeError: ‘FigureCanvasInterAgg‘ object has no attribute ‘tostring_rgb‘. Did y

解决matplotlib报错: AttributeError: ‘FigureCanvasInterAgg‘ object has no attribute ‘tostring_rgb‘. Did y

解决matplotlib报错: AttributeError: ‘FigureCanvasInterAgg’ object has no attribute ‘tostring_rgb’. Did you mean: ‘tostring_argb’?


报错原因:
PyCharm 自带的 pycharm_matplotlib_backend 与新版本 matplotlib 不兼容
新版 matplotlib 移除了 tostring_rgb,仅保留 tostring_argb
PyCharm 的内置绘图后端插件还在调用旧接口,触发属性缺失异常
import matplotlib

# 切换后端,可选 agg / TkAgg / Qt5Aggmatplotlib.use('Agg')importmatplotlib.pyplotasplt

最顶部添加,切换 matplotlib 后端,不使用 PyCharm 自带 InterAgg 后端
添加之后就可以显示出图像来了

返回列表