Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plot exception: 'seaborn-whitegrid' is not a valid package style, path of style file #156

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

csrgxtu
Copy link

@csrgxtu csrgxtu commented Aug 1, 2024

when you use adtk==0.6.2 and plot the data, you will get following, that's because the matplotlib which is required by adtk installed don't have seaborn-whitegrid in recent versions. for styles available, you can refer: https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html

image

from adtk.visualization import plot
from matplotlib import style
plot(s_train) # s_train is loaded before.

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
File ~/.pyenv/versions/3.12.1/envs/ad/lib/python3.12/site-packages/matplotlib/style/core.py:137, in use(style)
    136 try:
--> 137     style = _rc_params_in_file(style)
    138 except OSError as err:

File ~/.pyenv/versions/3.12.1/envs/ad/lib/python3.12/site-packages/matplotlib/__init__.py:870, in _rc_params_in_file(fname, transform, fail_on_error)
    869 rc_temp = {}
--> 870 with _open_file_or_url(fname) as fd:
    871     try:

File ~/.pyenv/versions/3.12.1/lib/python3.12/contextlib.py:137, in _GeneratorContextManager.__enter__(self)
    136 try:
--> 137     return next(self.gen)
    138 except StopIteration:

File ~/.pyenv/versions/3.12.1/envs/ad/lib/python3.12/site-packages/matplotlib/__init__.py:847, in _open_file_or_url(fname)
    846 fname = os.path.expanduser(fname)
--> 847 with open(fname, encoding='utf-8') as f:
    848     yield f

FileNotFoundError: [Errno 2] No such file or directory: 'seaborn-whitegrid'

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

OSError                                   Traceback (most recent call last)
Cell In[2], line 3
      1 from adtk.visualization import plot
      2 from matplotlib import style
----> 3 plot(s_train)

File ~/.pyenv/versions/3.12.1/envs/ad/lib/python3.12/site-packages/adtk/visualization/_visualization.py:201, in plot(ts, anomaly, curve_group, ts_linewidth, ts_color, ts_alpha, ts_marker, ts_markersize, match_curve_name, anomaly_tag, anomaly_color, anomaly_alpha, anomaly_marker, anomaly_markersize, freq_as_period, axes, figsize, legend)
     35 """Plot time series and/or anomalies.
     36 
     37 Parameters
   (...)
    198 
    199 """
    200 # setup style
--> 201 plt.style.use("seaborn-whitegrid")
    203 # initialize color generator
    204 color_generator = ColorGenerator()

File ~/.pyenv/versions/3.12.1/envs/ad/lib/python3.12/site-packages/matplotlib/style/core.py:139, in use(style)
    137         style = _rc_params_in_file(style)
    138     except OSError as err:
--> 139         raise OSError(
    140             f"{style!r} is not a valid package style, path of style "
    141             f"file, URL of style file, or library style name (library "
    142             f"styles are listed in `style.available`)") from err
    143 filtered = {}
    144 for k in style:  # don't trigger RcParams.__getitem__('backend')

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`)

To use recent matplotlib versions, we need modify the logic in _visualization.plot, make it compatible with recent versions of matplotlib.

tailaiw and others added 2 commits April 16, 2020 21:27

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Merge v0.6.2 to branch develop
@csrgxtu
Copy link
Author

csrgxtu commented Aug 1, 2024

after modify, test it, and got following:
img_v3_02db_c674c7cd-3360-4316-8572-bb20cf52277g

@csrgxtu
Copy link
Author

csrgxtu commented Aug 1, 2024

@tailaiw @roycoding plz help review this PR.

@am2222
Copy link

am2222 commented Oct 18, 2024

Any chance this gets approved?

@tbenhamou
Copy link

Can you guys merge it please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants