beojan / atlas-mpl

ATLAS style for matplotlib
https://atlas-mpl.readthedocs.io/en/latest/index.html
GNU General Public License v3.0
14 stars 6 forks source link

ampl.use_atlas_style() not working from conda install. #9

Closed russbate42 closed 6 months ago

russbate42 commented 6 months ago

As per the docs, using ampl.use_atlas_style() throws the following error:

  File "\~/miniconda3/envs/HEP/lib/python3.9/site-packages/matplotlib/style/core.py", line 137, in use
    style = _rc_params_in_file(style) 
  File "\~/miniconda3/envs/HEP/lib/python3.9/site-packages/matplotlib/__init__.py", line 866, in _rc_params_in_file
    with _open_file_or_url(fname) as fd:
  File "\~/miniconda3/envs/HEP/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File "\~/miniconda3/envs/HEP/lib/python3.9/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: 'atlas'

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

Traceback (most recent call last):
  File "\~/Projects/sandbox/py_env_debug_matplotlib_atlas/test.py", line 8, in <module>
    ampl.use_atlas_style()
  File "\~/miniconda3/envs/HEP/lib/python3.9/site-packages/atlas_mpl_style/__init__.py", line 217, in use_atlas_style
    _style.use("atlas")
  File "\~/miniconda3/envs/HEP/lib/python3.9/site-packages/matplotlib/style/core.py", line 139, in use
    raise OSError(

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

Ubuntu 22.0.4 I am using the latest ROOT version with conda-forge 6.22/08 matplotlib: 3.8.4 atlas-mpl-style 0.21.0

the matplotlib config directory is in ~/.config/matplotlib and the atlas-mpl-style package is installed in ~/miniconda3/envs/HEP/lib/python3.9/site-packages/atlas_mpl_style

Following this: Customizing with style sheets

How can we get a conda environment to recognize 'atlas' as a valid style with this set up?

beojan commented 6 months ago

Can you provide your exact setup? Which packages have you installed from conda, and which with pip?

russbate42 commented 6 months ago

conda 24.3.0

name: HEP channels:

dependencies:

Everything has been installed with conda except atlas-mpl-style, has been installed with pip, as it does not seem to be downloadable from conda-forge.

beojan commented 6 months ago

I've just set up precisely that with:

conda create -n HEP root=6.22.8 python=3.9.10 root-dependencies=6.22.8 matplotlib=3.8.4 scipy=1.12.0 pynvim=0.5.0 jupyterlab=4.1.5 numpy=1.26.4 pip=24.0 awkward=2.1.4 pandas=2.0.0 uproot=5.0.13 root_numpy=4.8.0 scikit-hep=5.1.1 -c conda-forge
conda activate HEP
pip install atlas_mpl_style

Then I opened an IPython shell in the environment and ran

import matplotlib.pyplot as plt
import atlas_mpl_style as ampl
ampl.use_atlas_style()

With this, I don't get any errors. I can then make a plot with plt.plot([0, 4], [3, 3]) and the plot uses the ATLAS stylesheet.

Do you have anything else earlier in your code, or other customizations to your environment?

russbate42 commented 6 months ago

Ok I exported the environment, deleted it, rebuilt it, and re-installed atlas-mpl-style. This worked. There must have been some conflict in the environment that was causing problems. Thank you!