D:\chulishuju\main.py:486: 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.subplot(2, 5, i+1) Traceback (most recent call last): File "D:\chulishuju\main.py", line 502, in <module> main() File "D:\chulishuju\main.py", line 486, in main plt.subplot(2, 5, i+1) File "D:\2023.5.21\lib\site-packages\matplotlib\pyplot.py", line 1293, in subplot fig = gcf() File "D:\2023.5.21\lib\site-packages\matplotlib\pyplot.py", line 879, in gcf return figure() File "D:\2023.5.21\lib\site-packages\matplotlib\_api\deprecation.py", line 454, in wrapper return func(*args, **kwargs) File "D:\2023.5.21\lib\site-packages\matplotlib\pyplot.py", line 813, in figure manager = new_figure_manager( File "D:\2023.5.21\lib\site-packages\matplotlib\pyplot.py", line 382, in new_figure_manager _warn_if_gui_out_of_main_thread() File "D:\2023.5.21\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:\2023.5.21\lib\site-packages\matplotlib\pyplot.py", line 208, in _get_backend_mod switch_backend(rcParams._get("backend")) File "D:\2023.5.21\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-08-07 12:02:31 浏览: 162
这是 MatplotlibDeprecationWarning 的一个警告,目前还没有影响到代码的运行。但是,在未来的版本中将会移除对没有 required_interactive_framework 属性的 FigureCanvases 的支持。同时,也暴露出了关于 pyplot 的一个 TypeError。
为了避免这个问题,可以尝试更新 Matplotlib 的版本,或者在代码中将 plt.show() 函数放在所有 subplot() 函数之后调用。另外,也可以将代码中的 plt.subplot() 函数替换为 fig.add_subplot() 函数,以避免出现警告。
相关问题
/Users/dujun/opt/anaconda3/bin/python /Users/dujun/PycharmProjects/pythonProject1/main.py /Users/dujun/PycharmProjects/pythonProject1/main.py:4: 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.figure("results_img", figsize=(26,26)) /Users/dujun/PycharmProjects/pythonProject1/main.py:6: 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.show() 进程已结束,退出代码0
这个警告是由于Matplotlib库的版本升级导致的,它在3.6版本中引入了一个新的属性`required_interactive_framework`,并且将在未来的版本中删除不带该属性的FigureCanvases。
虽然这个警告可以忽略,但如果你想避免它,可以尝试更新Matplotlib库到最新版本。你可以使用以下命令来更新Matplotlib库:
```
pip install --upgrade matplotlib
```
如果你已经安装了最新版本的Matplotlib库,但仍然收到警告,请检查你的代码是否在其他地方使用了不再支持的特性或函数。
请注意,这个警告不会影响你的代码的运行,你可以继续进行开发和测试。如果你有其他问题,请随时提问。
D:\pythonProject1\main.py:144: 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.imshow(cm, cmap=plt.cm.Blues) D:\pythonProject1\main.py:154: 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.show() Traceback (most recent call last): File "D:\pythonProject1\main.py", line 185, in <module> y_true = y_test[np.arange(y_test.shape[0]), y.astype(str)] IndexError: arrays used as indices must be of integer (or boolean) type是什么意思,该如何修改
这个错误信息提示了两个问题:
1. MatplotlibDeprecationWarning:这是Matplotlib库中的一个警告,意味着你正在使用过时的方法来创建图形。它不是错误,但是建议你更新代码以使用新的方法来创建图形。
2. IndexError:这是一个错误,可能是由于使用了错误类型的索引。在你的代码中,你正在使用`y.astype(str)`创建一个字符串类型的数组,并将其用作索引,但是你不能使用字符串类型的数组作为索引。索引必须是整数或布尔类型。
为了解决这些问题,建议你更新Matplotlib库并使用整数或布尔类型的索引。你可以使用`int()`或`bool()`函数将数组转换为整数或布尔类型的索引。另外,也可以使用`np.array()`函数创建一个整数或布尔类型的索引数组。
阅读全文
相关推荐








