python的Matplotlib的AttributeError: 'NoneType' object has no attribute 'pyplot_show'
时间: 2023-06-22 21:22:05
浏览: 813
这个错误通常是由于没有正确导入Matplotlib库中的pyplot模块而导致的。你需要确保在[代码](https://geek.csdn.net/educolumn/1572ef9b473b4e00f6b2bf6d428b7c27?spm=1055.2569.3001.10083)中正确导入pyplot模块。例如:
import matplotlib.pyplot as plt
# 在这里添加你的[代码](https://geek.csdn.net/educolumn/1572ef9b473b4e00f6b2bf6d428b7c27?spm=1055.2569.3001.10083)
plt.show()
在这个例子中,我们使用plt作为pyplot模块的别名,并在[代码](https://geek.csdn.net/educolumn/1572ef9b473b4e00f6b2bf6d428b7c27?spm=1055.2569.3001.10083)的末尾调用plt.show()方法来[显示](https://geek.csdn.net/educolumn/103ca72607c717122e068b9f06a24df6?spm=1055.2569.3001.10083)图形。如果你仍然遇到问题,可能需要检查你的Matplotlib[版本](https://geek.csdn.net/educolumn/04449e2eb7da35a9c72dce97dbf43e2a?spm=1055.2569.3001.10083)是否正确安装。
相关问题
AttributeError: 'NoneType' object has no attribute 'pyplot_show'
### 回答1:
这个错误通常是由于未正确导入 matplotlib 库或者未正确使用 pyplot.show() 函数引起的。请确保在代码中正确导入 matplotlib 库,例如:
import matplotlib.pyplot as plt
```
matplotlib保存图片报错AttributeError: 'NoneType' object has no attribute 'pyplot_show'如何解决
这个错误通常是由于在调用 `pyplot.show()` 之前没有创建一个图形对象导致的。解决方法是在调用 `pyplot.show()` 之前创建一个图形对象,例如:
```python
import matplotlib.pyplot as plt
# 创建一个图形对象
fig = plt.figure()
# 绘制图形
plt.plot([1, 2, 3], [4, 5, 6])
# 保存图像
fig.savefig('figure.png')
# 显示图形
plt.show()
这样就可以成功保存图片并且不会出现上述错误了。
相关推荐













