return _get_backend_mod().show(*args, **kwargs) TypeError: __call__() takes 1 positional argument but 2 were given
时间: 2023-12-28 09:04:46 浏览: 460
这个错误通常出现在调用一个没有定义参数的函数时,而给了它一个参数。也可能是传递参数的方式不正确。
建议你检查一下你的代码,看看是否在调用函数时传递了多余的参数,或者传递参数的方式是否正确。你可以尝试使用更具体的参数名来调用函数,例如:
```
function_name(param_name=value)
```
这样可以避免参数位置不正确的问题。如果问题仍然存在,你可以尝试查看函数定义,确认参数的数量和名称是否正确。
相关问题
D:\pythonProject5\main.py:176: 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) D:\pythonProject5\main.py:178: 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(ecg_signal) Traceback (most recent call last): File "D:\pythonProject5\main.py", line 219, in <module> main() File "D:\pythonProject5\main.py", line 178, in main plt.show(ecg_signal) File "D:\Users\lenovo\anaconda3\lib\site-packages\matplotlib\pyplot.py", line 446, in show return _get_backend_mod().show(*args, **kwargs) TypeError: Show.__call__() takes 1 positional argument but 2 were given
这个错误是由于`plt.show()`函数的调用方式不正确导致的。`plt.show()`函数不需要传入参数,它会自动显示当前所有的绘图结果。您可以将代码修改为以下形式:
``` python
from matplotlib import pyplot as plt
# 绘制ECG信号,并在一张图片上展示多个画布
fig = plt.figure(figsize=(20, 10))
for i in range(10):
ax = fig.add_subplot(2, 5, i+1)
ax.plot(ecg_signal[i])
ax.set_title(f'ECG Signal {i+1}')
plt.show()
```
这里的`plt.show()`函数不需要传入参数,它会显示`fig`中的所有画布。如果您需要在多个画布中显示多个信号,可以使用`fig.add_subplot()`函数来创建子画布,并在每个子画布上绘制对应的信号。
Traceback (most recent call last): File "D:\PythonProject\数据分析\plot.py", line 39, in <module> dfgroup2.plot(kind="bar") File "D:\anaconda3\lib\site-packages\pandas\plotting\_core.py", line 1000, in __call__ return plot_backend.plot(data, kind=kind, **kwargs) File "D:\anaconda3\lib\site-packages\pandas\plotting\_matplotlib\__init__.py", line 71, in plot plot_obj.generate() File "D:\anaconda3\lib\site-packages\pandas\plotting\_matplotlib\core.py", line 451, in generate self._setup_subplots() File "D:\anaconda3\lib\site-packages\pandas\plotting\_matplotlib\core.py", line 512, in _setup_subplots fig = self.plt.figure(figsize=self.figsize) File "D:\anaconda3\lib\site-packages\matplotlib\_api\deprecation.py", line 454, in wrapper return func(*args, **kwargs) File "D:\anaconda3\lib\site-packages\matplotlib\pyplot.py", line 813, in figure manager = new_figure_manager( File "D:\anaconda3\lib\site-packages\matplotlib\pyplot.py", line 382, in new_figure_manager _warn_if_gui_out_of_main_thread() File "D:\anaconda3\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:\anaconda3\lib\site-packages\matplotlib\pyplot.py", line 208, in _get_backend_mod switch_backend(rcParams._get("backend")) File "D:\anaconda3\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
这个错误通常是因为你的matplotlib库的backend没有正确设置,或者你的代码在非交互式环境中运行。你可以尝试在代码的开头添加下面这行代码来设置matplotlib的backend:
```python
import matplotlib
matplotlib.use('TkAgg')
```
这里的'TkAgg'是一种常用的backend,你也可以根据自己的需要选择其他的backend。如果你已经设置了backend,但仍然出现这个错误,那么可能是你的代码在非交互式环境中运行。你可以尝试在交互式环境中运行代码,或者使用plt.savefig()函数将图像保存到文件中,而不是在窗口中显示。
阅读全文