Neither `from matplotlib.cm import register_cmap` nor `from matplotlib.colormaps import register` works in cooltools 0.7.1 for supporting `matplotlib 3.9`
This issue has been discussed in https://github.com/open2c/cooltools/issues/520. It is fixed in https://github.com/open2c/cooltools/pull/533.
try:
from matplotlib.cm import register_cmap
except ImportError:
from matplotlib.colormaps import register
However, this fix in cooltools/lib/plotting.py does not work for me.
>>> from matplotlib.cm import register_cmap
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'register_cmap' from 'matplotlib.cm' (/home/ljw/wuqiang/sx/sx_lcy/.conda/lib/python3.11/site-packages/matplotlib/cm.py)
and
>>> from matplotlib.colormaps import register
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'matplotlib.colormaps'
My package versions are
cooler 0.10.2 pyhdfd78af_0 bioconda
coolpuppy 1.1.0 pyh086e186_0 bioconda
cooltools 0.7.1 py311h1abe8b6_0 bioconda
hic2cool 1.0.1 pyh7cba7a3_0 bioconda
matplotlib 3.9.3 py311h38be061_0 conda-forge
matplotlib-base 3.9.3 py311h2b939e6_0 conda-forge
matplotlib-inline 0.1.7 pyhd8ed1ab_0 conda-forge
Can you please double check you are using the versions that you think you are using? Can you check the output of matplotlib.version and cooltools.version in the interactive python prompt where you tried running the code?
Python 3.11.10 | packaged by conda-forge | (main, Oct 16 2024, 01:27:36) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.__version__
'3.9.3'
>>> import cooltools
>>> cooltools.__version__
'0.7.1'
>>>
I use conda. Does that matter?
Hi, I'm having users report the same error from the quaich program (also from open2c) that uses cooltools and coolpuppy as well. Same matplotlib version 3.9.3 and cooltools 0.7.1
This was built using the conda environment built from the quaich program template/yaml file they provided. Some of the downstream tools must still reference deprecated calls to matplotlib that are now gone in 3.9.3.
I can confirm, for a fresh installation today:
- cooler via conda
- cooltools via pip I get the same error for Matplotlib 3.9.3. for now I simply downgraded matplotlib to 3.6.0 via pip.
I modified the code and it works now.
try:
from matplotlib.cm import register_cmap
except ImportError:
from matplotlib import colormaps
# from matplotlib.colormaps import register
def _register_cmaps():
for name, pal in PALETTES.items():
colormaps.register(list_to_colormap(pal), name=name)
colormaps.register(list_to_colormap(pal[::-1]), name=name + '_r')
# register_cmap(name, list_to_colormap(pal))
# register_cmap(name + "_r", list_to_colormap(pal[::-1]))
Will the fix be merged to version 0.7.2?