Reloading matplotlib overwrites custom settings
AKuederle opened this issue · 2 comments
Hi it seems like reloading matplotlib using imp
as you do on line 81 in scalebar.py
causes some issues with custom settings.
For example:
from matplotlib_scalebar.scalebar import ScaleBar
from matplotlib_scalebar.dimension import _Dimension
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams.update({'font.family': 'serif'})
As you can see the fonts are sans-serif and not serif.
Doing the same without importing matplotlib_scalebar, will lead to the expected result:
# from matplotlib_scalebar.scalebar import ScaleBar
# from matplotlib_scalebar.dimension import _Dimension
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams.update({'font.family': 'serif'})
By playing around with a local install of your package I could verify, that reloading matplotlib (line 81) causes this issue.
imp.reload(sys.modules['matplotlib'])
Removing that line resolves the issue and does not seem to change anything else. (all test still work and all other things I tested, too)
Could you explain what the original intention of this line was?
Best regards,
Arne
(PS: awesome package otherwise! Saved me a lot of time!)
Thank you for reporting the issue. The intention of the imp.reload(...)
is to allow the definition of new parameters in matplotlibrc. For instance, if you comment out line 81, the following throws an error:
matplotlib.rcParams['scalebar.box_color'] = 'r'
KeyError: 'scalebar.box_color is not a valid rc parameter.See rcParams.keys() for a list of valid parameters.'
I tried another approach in commit db3d48b where I only reload the validate
method from RcParams
. It seems to fix the problem, but please let me know if you find other limitations.
Thank you very much for fixing this so fast! From my side it looks like it is working.