import matplotlib.pyplot as plt报错

在使用intellij idea时,当通过如下方式使用时,matplotlib.pyplot导入报错,使用方法如下:

import matplotlib.pyplot as plt

# 创建一个图形和一个子图
fig, ax = plt.subplots()

其中,会出现诸如module ‘matplotlib.pyplot’ has no attribute 'switch_backend’等问题。

解决方案

更好更低版本的matplotlib即可。

步骤一:卸载原有matplotlib:

pip3 uninstall matplotlib

步骤二:安装指定低版本的matplotlib::

pip3 install matplotlib==2.2.3

当然,也可以将上述版本信息配置到requirements.txt配置文件当中。

另外还有一种错误原因,就是自定义package中有matplotlib,在引用时应用了自定义的Matplotlib而不是类库中的。

猜你喜欢

转载自blog.csdn.net/wo541075754/article/details/131163248