Where to put site style file

I preinstall matplotlib in /usr/local so that it is preinstalled for users of a container.

I have a file foo.mplstyle file that I put at $(matplotlib.get_data_path()). Users can activate it with matplotlib.style.use('foo'). I’m not sure if this is the right way to do what I want, but it works fine.

The problem is that some users install a copy of matplotlib in their home directory or a virtual environment. They therefore lose access too foo.mplstyle because it is not in “their” matplotlib.get_data_path().

I know I can pass a path to matplotlib.style.use, but I would prefer not to do that (the style will not show up in matplotlib.style.available, among other problems).

So I’m looking for a global path that all copies of matplotlib will search for styles. Does this exist? Or can it be configured?

No, the aim of virtual environments is to isolate from the global environment. There is unfortunately no global outside-of-the-install location that is searched.

As you say, people can pass absolute paths to matplotlib.style.use. Since you’re in a container, you could drop it in /, and then the absolute path is quite close, being /name.mplstyle. But this won’t appear in matplotlib.style.available.

As an opposite to a global location, there is a user-specific path, ~/.config/matplotlib/stylelib (or os.path.join(mpl.get_configdir(), 'stylelib')). Again, since you’re in a container, I expect it will be single-user, so dropping a symlink in there to the global, or putting the style there directly would be safe. This one will show up in matplotlib.style.available.

Got it. That makes sense. Thank you!