我在PyCharm中运行以下代码:
import matplotlib.pyplot as plt
import numpy as np
# Data for plotting
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
fig, ax = plt.subplots()
ax.plot(t, s)
ax.set(xlabel='time (s)', ylabel='voltage (mV)',
title='About as simple as it gets, folks')
ax.grid()
fig.savefig("test.png")
plt.show()
字符串
我以前已经让它工作了。突然它返回以下错误:
Traceback (most recent call last):
File "C:\Users\NoraBuggy\PycharmProjects\pythonProject\main.py", line 8, in <module>
fig, ax = plt.subplots()
File "C:\Users\NoraBuggy\miniconda3\lib\site-packages\matplotlib\pyplot.py", line 1598, in subplots
fig = figure(**fig_kw)
File "C:\Users\NoraBuggy\miniconda3\lib\site-packages\matplotlib\pyplot.py", line 934, in figure
manager = new_figure_manager(
File "C:\Users\NoraBuggy\miniconda3\lib\site-packages\matplotlib\pyplot.py", line 465, in new_figure_manager
return _get_backend_mod().new_figure_manager(*args, **kwargs)
File "C:\Users\NoraBuggy\miniconda3\lib\site-packages\matplotlib\backend_bases.py", line 3396, in new_figure_manager
return cls.new_figure_manager_given_figure(num, fig)
File "C:\Users\NoraBuggy\miniconda3\lib\site-packages\matplotlib\backend_bases.py", line 3401, in new_figure_manager_given_figure
return cls.FigureCanvas.new_manager(figure, num)
File "C:\Users\NoraBuggy\miniconda3\lib\site-packages\matplotlib\backend_bases.py", line 1785, in new_manager
return cls.manager_class.create_with_canvas(cls, figure, num)
File "C:\Users\NoraBuggy\miniconda3\lib\site-packages\matplotlib\backend_bases.py", line 2680, in create_with_canvas
return cls(canvas_class(figure), num)
File "C:\Users\NoraBuggy\miniconda3\lib\site-packages\matplotlib\backends\backend_qt.py", line 522, in __init__
super().__init__(canvas, num)
File "C:\Users\NoraBuggy\miniconda3\lib\site-packages\matplotlib\backend_bases.py", line 2654, in __init__
self.toolbar = self._toolbar2_class(self.canvas)
File "C:\Users\NoraBuggy\miniconda3\lib\site-packages\matplotlib\backends\backend_qt.py", line 669, in __init__
NavigationToolbar2.__init__(self, canvas)
File "C:\Users\NoraBuggy\miniconda3\lib\site-packages\matplotlib\backend_bases.py", line 2844, in __init__
self._nav_stack = cbook._Stack()
File "C:\Users\NoraBuggy\miniconda3\lib\site-packages\matplotlib\_api\__init__.py", line 217, in __getattr__
raise AttributeError(
AttributeError: module 'matplotlib.cbook' has no attribute '_Stack'
Process finished with exit code 1
型
Matplotlib今天早些时候工作正常。这个错误是在我尝试使用seaborn绘制一些东西后开始的,这给了我一个类似的错误,所以我删除了seaborn。现在,当我尝试绘制任何东西时,我都会遇到这个错误消息。
我看到一个similar post建议确保你没有安装多个版本的matplotlib。
我在pycharm终端中运行了以下代码:
conda list matplotlib
型
这给了我这个:
# packages in environment at C:\Users\NoraBuggy\miniconda3:
#
# Name Version Build Channel
matplotlib 3.6.2 pypi_0 pypi
matplotlib-base 3.8.0 py39h4ed8f06_0
型
我尝试卸载matplotlib-base,然后import matplotlib.pyplot as plt
给我一个错误,matplotlib没有安装。
1条答案
按热度按时间fnvucqvd1#
unistall matplotlib并尝试以下操作:
字符串
试试这个
型