-
Notifications
You must be signed in to change notification settings - Fork 12
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
Avoid changing matplotlib rcParams font size #142
Avoid changing matplotlib rcParams font size #142
Conversation
Even with this PR, something screwy is still happening that's messing up one of the other plots produced by code in webbpsf, if I import spaceKLIP before running that other function. Very weird and confusing. Continuing to investigate... |
Found it. The other side effects that were/are messing up my plotting code come from |
Attach a context manager decorator to all plotting functions in plotting.py such that they load the spaceKLIP style sheet file. This way it doesn't touch the default matplotlib rcparams dictionary.
add context manager and decorator matplotlib style to various plotting routines around spaceklip.
Okay, so in order to keep things consistent with plotting styles, but not break the default matplotlib rcparams configuration, I have updated both In addition, matplotlib allows for adding context manager decorators to any code to temporarily load this style sheet, so I have gone through all plotting calls in the various .py files and added these decorators to use dynamically use the previously hardcoded rcparams. This means there should be no apparent change in the spaceklip plotting functions, but other packages (such as webbpsf) will not be affected. If you want to use these context managers, you would simply do the following: with plt.style.context('spaceKLIP.sk_style'):
fig, ax = plt.sublots()
some_plotting_function(ax)
another_function(ax)
fig.save()
plt.close(fig) Or when defining a function, add a decorator: @plt.style.context('spaceKLIP.sk_style')
def plotting_function(*args, **kwargs):
plt.plot(*args, **kwargs) |
Also, lots of cool pre-defined matplotlib styles here: https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a straight-forward change and I fully agree with it.
import spaceKLIP
should not have side effects that unexpectedly change the appearance of plots produced by other non-spaceKLIP code. In particular we shouldn't hard-code overrides to a user's default matplotlib settings in rcParams.