Matplotlib - Seaborn-whitegrid 不是有效的包样式

问题描述 投票:0回答:1

我使用 ADTK 进行异常检测,使用 matplotlib 进行可视化,但在尝试运行程序时遇到错误。这是我的代码,我使用 python3 运行

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

 
from adtk.data import validate_series
from adtk.visualization import plot
from adtk.detector import PersistAD

data = pd.read_csv('SQL_bytes_sent_ferdig.csv', index_col="time", parse_dates=True)
# Convert the index to a DatetimeIndex explicitly if it's not already
data.index = pd.to_datetime(data.index, utc=True)

# Add 1 hour to the index
data.index = data.index + pd.Timedelta(hours=1)
data_valid = validate_series(data)


persist_ad = PersistAD(c=3.0, side='positive')
anomalies = persist_ad.fit_detect(data_valid)

plot(data_valid, anomaly=anomalies, ts_linewidth=1, ts_markersize=3, anomaly_markersize=3, anomaly_color='red', anomaly_tag="marker");

运行此命令会出现以下错误:

/home/ubuntu/ad/sql_ad.py:1: DeprecationWarning:
Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0),
(to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries)
but was not found to be installed on your system.
If this would cause problems for you,
please provide us feedback at https://github.com/pandas-dev/pandas/issues/54466

  import pandas as pd
/home/ubuntu/.local/lib/python3.10/site-packages/adtk/detector/_detector_1d.py:270: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value 'nan' has dtype incompatible with bool, please explicitly cast to a compatible dtype first.
  predicted[s.isna()] = np.nan
/home/ubuntu/.local/lib/python3.10/site-packages/adtk/detector/_detector_1d.py:141: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value 'nan' has dtype incompatible with bool, please explicitly cast to a compatible dtype first.
  predicted[s.isna()] = np.nan
/home/ubuntu/.local/lib/python3.10/site-packages/adtk/aggregator/_aggregator.py:211: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value 'nan' has dtype incompatible with bool, please explicitly cast to a compatible dtype first.
  predicted[predicted & lists.isna().any(axis=1)] = float("nan")
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.10/site-packages/matplotlib/style/core.py", line 137, in use
    style = _rc_params_in_file(style)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/matplotlib/__init__.py", line 866, in _rc_params_in_file
    with _open_file_or_url(fname) as fd:
  File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/matplotlib/__init__.py", line 843, in _open_file_or_url
    with open(fname, encoding='utf-8') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'seaborn-whitegrid'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ubuntu/ad/sql_ad.py", line 22, in <module>
    plot(data_valid, anomaly=anomalies, ts_linewidth=1, ts_markersize=3, anomaly_markersize=3, anomaly_color='red', anomaly_tag="marker");
  File "/home/ubuntu/.local/lib/python3.10/site-packages/adtk/visualization/_visualization.py", line 201, in plot
    plt.style.use("seaborn-whitegrid")
  File "/home/ubuntu/.local/lib/python3.10/site-packages/matplotlib/style/core.py", line 139, in use
    raise OSError(
OSError: 'seaborn-whitegrid' is not a valid package style, path of style file, URL of style file, or library style name (library styles are listed in `style.available`)

我查看了其他具有类似问题的帖子,并尝试指定在我的代码中使用哪种样式,其中我有以下样式:

import matplotlib.pyplot as plt
# plt.style.use(['science', 'notebook'])
print(plt.style.available)

给予:

['Solarize_Light2', '_classic_test_patch', '_mpl-gallery', '_mpl-gallery-nogrid', 'bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn-v0_8', 'seaborn-v0_8-bright', 'seaborn-v0_8-colorblind', 'seaborn-v0_8-dark', 'seaborn-v0_8-dark-palette', 'seaborn-v0_8-darkgrid', 'seaborn-v0_8-deep', 'seaborn-v0_8-muted', 'seaborn-v0_8-notebook', 'seaborn-v0_8-paper', 'seaborn-v0_8-pastel', 'seaborn-v0_8-poster', 'seaborn-v0_8-talk', 'seaborn-v0_8-ticks', 'seaborn-v0_8-white', 'seaborn-v0_8-whitegrid', 'tableau-colorblind10']

但是它们都没有改变错误。在 Jupytor Notebook 中运行它可以工作,我什至不必指定要使用哪个图。我尝试使用 pip 安装seaborn,但仍然不起作用。

python matplotlib
1个回答
0
投票

@Elias Rudsbråten,我也遇到了这个问题,我通过将

seaborn-whitegrid
替换为
seaborn-v0_8-white grid
来修复它。我很好奇你最终能否找到
seaborn-white grid
的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.