PyCharm使用matplotlib:报MatplotlibDeprecationWarning.问题已解决

问题描述:

这个错误全部显示为:MatplotlibDeprecationWarning: Support for FigureCanvases without a required_interactive_framework attribute was deprecated in Matplotlib 3.6 and will be removed two minor releases later.
报错截图如下所示:在这里插入图片描述
代码示例:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0, 10, 0.1)
y = np.sin(x)
plt.plot(x, y)
plt.show()
plt.plot(x, y, ‘r’, label=‘sin(x)’)
plt.xlabel(‘x’)
plt.ylabel(‘y’)
plt.title(‘Sin Wave’)
plt.legend()
plt.show()

原因定位:

使用了过高版本的matplotlib库

查看matplotlib库版本信息

在这里插入图片描述

问题解决

安装低版本matplotlib即可
查看与当前matplotlib版本是否匹配当前python环境,可参考这个网址https://pypi.org/project/matplotlib/3.2.0/#history
应该安装该版本:
在这里插入图片描述
卸载不匹配的版本:
在这里插入图片描述
安装时matplotlib版本
在这里插入图片描述

问题验证:
在这里插入图片描述
重新运行:
在这里插入图片描述
安装合适的低版本matplotlib,问题就解决了

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>