ppinard / matplotlib-colorbar

Provides a new artist for matplotlib to display a colorbar
BSD 2-Clause "Simplified" License
7 stars 3 forks source link

UserWarning: This call to matplotlib.use() has no effect #9

Closed yoavram closed 6 years ago

yoavram commented 7 years ago

When importing from matplotlib_colorbar.colorbar import Colorbar after matplotlib has already been imported, say with %matplotlib inline, a warning comes up:

/Users/username/anaconda3/envs/scipy/lib/python3.6/site-packages/ipykernel/__main__.py:8: UserWarning: 
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

I managed to trace the warning, and it's coming from matplotlib_colorbar/colorbar.py, line 83:

imp.reload(sys.modules['matplotlib'])

If this is OK, maybe you can suppress the warning?

import warnings
with warnings.catch_warnings():
    warnings.simplefilter("ignore", UserWarning)
    imp.reload(sys.modules['matplotlib'])
ppinard commented 6 years ago

Thank you for reporting this bug. I saw the same warning message in my other package matplotlib-scalebar. I applied the same fix to matplotlib-colorbar which consists in reinitializing only the validate function.

matplotlib.rcParams.validate = \
    dict((key, converter) for key, (default, converter) in
         six.iteritems(defaultParams)
         if key not in matplotlib._all_deprecated)

It seems to work on my system, but I would appreciate if you have time to check it on yours. If it works, I will release a new version.

yoavram commented 6 years ago

Commit 6b4737290465d3daee0c46088f6842714f768a61 seems to be working fine!

ppinard commented 6 years ago

In release 0.3.5