F:\Deeplearning\Plot\Log.py:7: MatplotlibDeprecationWarning: Support for FigureCanvases without a required_interactive_framework attribute was deprecated in Matplotlib 3.6 and will be removed two minor releases later. plt.plot(x, y, 'r-', linewidt=3) Traceback (most recent call last): File "F:\Deeplearning\Plot\Log.py", line 7, in <module> plt.plot(x, y, 'r-', linewidt=3) File "D:\py\Python3\lib\site-packages\matplotlib\pyplot.py", line 2785, in plot return gca().plot( File "D:\py\Python3\lib\site-packages\matplotlib\pyplot.py", line 2282, in gca return gcf().gca() File "D:\py\Python3\lib\site-packages\matplotlib\pyplot.py", line 879, in gcf return figure() File "D:\py\Python3\lib\site-packages\matplotlib\_api\deprecation.py", line 454, in wrapper return func(*args, **kwargs) File "D:\py\Python3\lib\site-packages\matplotlib\pyplot.py", line 813, in figure manager = new_figure_manager( File "D:\py\Python3\lib\site-packages\matplotlib\pyplot.py", line 382, in new_figure_manager _warn_if_gui_out_of_main_thread() File "D:\py\Python3\lib\site-packages\matplotlib\pyplot.py", line 360, in _warn_if_gui_out_of_main_thread if _get_required_interactive_framework(_get_backend_mod()): File "D:\py\Python3\lib\site-packages\matplotlib\pyplot.py", line 208, in _get_backend_mod switch_backend(rcParams._get("backend")) File "D:\py\Python3\lib\site-packages\matplotlib\pyplot.py", line 331, in switch_backend manager_pyplot_show = vars(manager_class).get("pyplot_show") TypeError: vars() argument must have __dict__ attribute
时间: 2023-07-21 12:24:07 浏览: 71
这个错误包含了两个部分。第一部分是 `MatplotlibDeprecationWarning`,这是因为在 Matplotlib 3.6 中,`FigureCanvas` 类需要有一个 `required_interactive_framework` 属性。如果没有这个属性,会发出警告。这个警告在未来版本中会被移除。解决这个警告的方法是更新到 Matplotlib 3.6 或更高版本,或者在创建 `FigureCanvas` 对象时设置 `required_interactive_framework` 属性。
第二部分错误是 `TypeError: vars() argument must have __dict__ attribute`,这是因为 `vars()` 函数的参数必须是有 `__dict__` 属性的对象,但是 `manager_class` 没有这个属性。这个问题可能是由于 Matplotlib 的版本不兼容造成的。建议检查你的代码中使用的 Matplotlib 版本是否与其他库兼容,并更新到最新版本。
相关问题
MatplotlibDeprecationWarning: Support for FigureCanvases without a required_interactive_framework attribute was deprecated in Matplotlib 3.6 and will be removed two minor releases later. plt.plot(scores)
这个警告是由于在 Matplotlib 3.6 版本中废弃了对没有 `required_interactive_framework` 属性的 FigureCanvases 的支持,该警告将在两个次要版本之后被移除。这意味着在将来的版本中,如果你的代码中使用了这样的 FigureCanvases,将会引发错误。
要解决这个问题,你可以考虑更新你的代码,以使用具有 `required_interactive_framework` 属性的 FigureCanvases。在大多数情况下,这个属性默认为 `None`,所以你可以在代码中显式地设置它。例如,你可以使用以下代码来创建图形:
```python
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot(scores)
canvas = fig.canvas
canvas.required_interactive_framework = 'your_framework_name'
```
在这里,你需要将 `'your_framework_name'` 替换为你正在使用的交互式框架的名称,如 `'TkAgg'` 或 `'Qt5Agg'` 等。
这样做应该可以消除警告并确保你的代码在将来的版本中仍然正常运行。
E:\bigHome\book\KNN1.py:90: MatplotlibDeprecationWarning: Support for FigureCanvases without a required_interactive_framework attribute was deprecated in Matplotlib 3.6 and will be removed two minor releases later. plt.plot(k_range, k_scores)
这个警告是由于 Matplotlib 库的版本更新导致的,提示你使用的代码中的某些部分在未来可能会被删除。具体来说,警告中提到的是 FigureCanvases 没有 required_interactive_framework 属性,这个属性是 Matplotlib 3.6 引入的新特性。
虽然这个警告不会影响你的程序运行,但建议你将代码中的 FigureCanvas 替换为新的 FigureCanvasTkAgg,以避免警告。具体来说,你需要在代码中添加以下几行:
```python
import matplotlib
matplotlib.use('TkAgg')
```
然后,在绘制图像时,使用 FigureCanvasTkAgg 替代 FigureCanvas,例如:
```python
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
figure = plt.figure(figsize=(5, 4))
canvas = FigureCanvasTkAgg(figure, master=window)
canvas.get_tk_widget().pack()
```
这样就可以避免这个警告,并且确保代码在未来的 Matplotlib 版本中仍然可以正常运行。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)