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

Avoid overwrite of matplotlib.rcParamsDefault #460

Open
DanShort12 opened this issue Jun 10, 2020 · 1 comment
Open

Avoid overwrite of matplotlib.rcParamsDefault #460

DanShort12 opened this issue Jun 10, 2020 · 1 comment

Comments

@DanShort12
Copy link

Hi folks,

We've started using OpenMOC for some simulations, and it's broadly working very well - thanks!

I think I've hit on an issue when integrating your package with ours though, in that when I import openmoc a bunch of our plotting styles get overwritten. It looks like the issue relates to this section of code in plotter.py:

# Default matplotlib parameters to use in all plots
matplotlib_rcparams = matplotlib.rcParamsDefault
matplotlib_rcparams['font.family'] = 'sans-serif'
matplotlib_rcparams['font.weight'] = 'normal'
matplotlib_rcparams['font.size'] = 15
matplotlib_rcparams['savefig.dpi'] = 500
matplotlib_rcparams['figure.dpi'] = 500

In this you're overwriting matplotlib's default rcParams (rcParamsDefault). I suspect that isn't an intended side-effect of that code block - in particular it clashes with the functionality in e.g. matplotlib.rcdefault(), which resets the current rcParams to the matplotlib defaults. We generally reset the rcParams to defaults first when plotting in case a third party package that we've called has applied their own styling (like in the case with OpenMOC).

I think it's more likely that your intended usage is:

# Default matplotlib parameters to use in all plots
matplotlib_rcparams = matplotlib.rcParams
matplotlib_rcparams['font.family'] = 'sans-serif'
matplotlib_rcparams['font.weight'] = 'normal'
matplotlib_rcparams['font.size'] = 15
matplotlib_rcparams['savefig.dpi'] = 500
matplotlib_rcparams['figure.dpi'] = 500

This behaviour can fairly easily be reproduced by executing the following:

import matplotlib.pyplot as plt

# Make a plot without setting any rcParams (i.e. using the defaults)
plt.plot([1, 2, 3, 4])
plt.ylabel("some numbers")
plt.savefig("before.png")

# Import OpenMOC
import openmoc

# Reset rcParams to default and save (should do nothing as we didn't set any rcParams above)
plt.rcdefaults()
plt.savefig("after.png")

Note that after.png has been set to a higher resolution (thus has a larger file size) than before.png by the update to savefig.dpi in plotter.py. Of course our actual styling is more complex that that, but I think this highlights the issue.

Cheers,
Dan

@GiudGiud
Copy link
Contributor

Thanks for pointing that out. I'll look into it and push a fix soon.

Glad OpenMOC is of use to you. Please feel free to raise more issues if you see anything that can be improved / fixed.

Best,
Guillaume

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

No branches or pull requests

2 participants