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

Neither from matplotlib.cm import register_cmap nor from matplotlib.colormaps import register works in cooltools 0.7.1 for supporting matplotlib 3.9 #544

Open
ljw20180420 opened this issue Dec 11, 2024 · 6 comments

Comments

@ljw20180420
Copy link

This issue has been discussed in #520. It is fixed in #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
@Phlya
Copy link
Member

Phlya commented Dec 11, 2024

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?

@ljw20180420
Copy link
Author

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?

@bgizelarMCW
Copy link

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.

@cchlanger
Copy link

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.

@WANGchuang715
Copy link

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]))

@ljw20180420
Copy link
Author

Will the fix be merged to version 0.7.2?

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

5 participants