如何忽略这一警告 D:\Anaconda3\envs\mathematical\lib\site-packages\matplotlib\cbook\__init__.py:1298: ComplexWarning: Casting complex values to real discards the imaginary part return np.asarray(x, float
时间: 2023-05-25 15:02:18 浏览: 465
)A: 可以使用以下代码将警告过滤掉:
```
import warnings
warnings.filterwarnings("ignore", category=ComplexWarning)
```
相关问题
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()函数将图像保存到文件中,而不是在窗口中显示。
Traceback (most recent call last): File "F:\pythonproject\ARIMA-GRACH\4.py", line 37, in <module> plt.fill_between(test_data.index, forecast_upper, forecast_lower, color='gray', alpha=0.2) File "E:\anaconda\lib\site-packages\matplotlib\pyplot.py", line 2543, in fill_between return gca().fill_between( File "E:\anaconda\lib\site-packages\matplotlib\__init__.py", line 1412, in inner return func(ax, *map(sanitize_sequence, args), **kwargs) File "E:\anaconda\lib\site-packages\matplotlib\axes\_axes.py", line 5252, in fill_between return self._fill_between_x_or_y( File "E:\anaconda\lib\site-packages\matplotlib\axes\_axes.py", line 5173, in _fill_between_x_or_y where = where & ~functools.reduce( ValueError: operands could not be broadcast together with shapes (180,) (64800,)
这个错误是因为 `forecast_upper` 和 `forecast_lower` 的长度与 `test_data.index` 不匹配,导致无法进行填充操作。你需要检查一下这两个变量的长度是否正确,并且与 `test_data.index` 保持一致。如果长度不一致,你需要重新计算 `forecast_upper` 和 `forecast_lower`,使它们的长度与 `test_data.index` 保持一致。
阅读全文