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

Unable to provide configuration via environmental variable #68

Open
ascended121 opened this issue Jan 8, 2024 · 1 comment
Open

Unable to provide configuration via environmental variable #68

ascended121 opened this issue Jan 8, 2024 · 1 comment

Comments

@ascended121
Copy link

I'm attempting to configure mplcursors via the following code:

import os
os.environ["MPLCURSORS"] = '{"hover": 1}'
import mplcursors

however this doesn't appear to work... no cursors appear when I click on the resulting plots. I'm not sure why, because my understanding is that this sets env vars for the python process. Seems that setting the env vars before mplcursors is imported would cause it to see them, just as if they had been set at the CLI.

When I call my script via

MPLCURSORS='{"hover": 1}' python3 my_script.py

I see cursors as expected.

I'd like to be able to globally configure cursors (since I have a lot of plots), but I don't want the user to have to remember to set env vars when they invoke the script, which is why I'm trying to set them in the code itself.

Is this method of setting env variables expected to work? Does it matter where the env var is set relative to the mplcursors import? Or relative to the matplotlib import?

Is there an easier way of configuring mplcursors globally without using env vars? Perhaps a module variable that could be set?

@anntzer
Copy link
Owner

anntzer commented Jan 9, 2024

Setting the environment variable a posteriori is not expected to work given the way things are implemented right now. It would indeed be nice if it did; ideally registration should be rewritten to be based on the new rcParams["figure.hooks"] system but I can't promise any timeline for that. (There's no other global config available either.)

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

No branches or pull requests

2 participants