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

OSError on 'science' as not a valid package style, path of style file, URL of style file, or library style name in v 2.0.1 #89

Closed
dhakalnirajan opened this issue Apr 10, 2023 · 2 comments
Labels
user question/help Issues regarding questions or help requests

Comments

@dhakalnirajan
Copy link

Hi!

I loved using SciencePlots and I came back to Python after learning C, and many thanks for helping other folks out and me with the project!

I was using v 2.0.1 in Google Colab, and I cannot use the science style.

I did the following:

!pip install SciencePlots

import scienceplots
import matplotlib.pyplot as plt


plt.style.reload_library()

plt.style.use(['science', 'notebook', 'grid'])

And the generated error was the following:

FileNotFoundError: [Errno 2] No such file or directory: 'science'

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

OSError                                   Traceback (most recent call last)
[/usr/local/lib/python3.9/dist-packages/matplotlib/style/core.py](https://localhost:8080/#) in use(style)
    166                 style = _rc_params_in_file(style)
    167             except IOError as err:
--> 168                 raise IOError(
    169                     f"{style!r} is not a valid package style, path of style "
    170                     f"file, URL of style file, or library style name (library "

OSError: 'science' 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`)

How can I work on that issue?

Thanks!

@echedey-ls
Copy link
Collaborator

You don't have to reload the styles library. Remove plt.style.reload_library().

In the older versions, that was needed as SciencePlots copied the styles into Matplotlib default styles folder. After copying them you had to tell Matplotlib to update its styles. With the new version, importing SciencePlots registers new styles from the package folder, so if the library is reloaded after the import matplotlib statement, Matplotlib 'forgets' the SciencePlots ones.

Anyways, is that code from an example you found in current docs? I may have missed to update something.

@dhakalnirajan
Copy link
Author

dhakalnirajan commented Apr 10, 2023

Hi @echedey-ls !

I tried the latest commit way using the code

!pip install git+https://github.com/garrettj403/SciencePlots

import scienceplots
import matplotlib.pyplot as plt

plt.style.use(['science', 'notebook', 'ieee'])

It worked.

Thanks!

If anyone is facing the error, you need to remove:

plt.style.reload_library()

if you have this code snippet as mpl removes the style from scienceplots library.

@echedey-ls echedey-ls added the user question/help Issues regarding questions or help requests label Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user question/help Issues regarding questions or help requests
Projects
None yet
Development

No branches or pull requests

2 participants