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

Global rcParams change on import #81

Closed
OnDraganov opened this issue Jul 17, 2024 · 5 comments · Fixed by #82
Closed

Global rcParams change on import #81

OnDraganov opened this issue Jul 17, 2024 · 5 comments · Fixed by #82
Labels
bug Something isn't working

Comments

@OnDraganov
Copy link

In persim/landscapes/visuals.py, line 15 defines mpl.rcParams["text.usetex"] = True. This means that whenever we import persim, the behavior of pyplot changes to that setting in all the pyplot uses. This is undesirable, as the user might prefer the default pyplot options for other uses than calls through persim.

If TeX rendering is necessary for the plots, is it possible to do the change only locally whenever a plot is created? It could be done using with mpl.rc_context({"text.usetex": True}): construction or by passing usetex=True at the individual places where it is desired.

@catanzaromj
Copy link
Contributor

Thanks for the issue @OnDraganov. Absolutely! I agree that this shouldn't be set as a global. I believe we only use TeX for subscripts and superscripts in a mathematician friendly way. I think the context manager mpl.rc_context is a great way to deal with this. Are you interested in submitting a PR to implement the change?

@catanzaromj catanzaromj added the bug Something isn't working label Jul 17, 2024
@maximelucas
Copy link
Contributor

maximelucas commented Jul 18, 2024

I've just encountered the same problem.

If TeX is only used for subscripts and superscripts, it might not be necessary at all?
Default math rendering by matplotlib does this already. In that case, I would remove the line entirely and let the user choose to turn TeX if they want to (I'm happy to submit a PR for that).

Unless you use specific characters with which it may not work?

@catanzaromj
Copy link
Contributor

@maximelucas The layers of the landscapes (indexed over depth) are typically denoted with $\lambda$, but I don't think we need latex for that. I think we can just use unicode characters, as shown in the updated answer here. If you agree, then please submit a PR implementing that change.

@OnDraganov
Copy link
Author

I tried and r$\lambda_{2}$ actually shows correctly even with matplotlib.rcParams['text.usetex'] being False (matplotlib version 3.8.4). So just erasing the 15 should be enough. Is that worth a pull request?

@maximelucas
Copy link
Contributor

Yes most of the time it works even without the "r" in front.
I just created a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants