holoviz / colorcet

A set of useful perceptually uniform colormaps for plotting scientific data
http://colorcet.holoviz.org
Other
673 stars 52 forks source link

matplotlib.cm.get_cmap returns a copy in 3.6.0 #89

Closed QuLogic closed 1 year ago

QuLogic commented 1 year ago

ALL software version info

colorcet 39af94a; Python 3.11; Matplotlib 3.6.0rc1

Description of expected behavior and the observed behavior

As noted in the get_cmap docstring, it will return a copy in 3.6. This has taken effect in 3.6.0rc1, and is causing tests that assume that to break. See test downstream build in Fedora.

Stack traceback and/or browser JavaScript console output

_______________ test_get_cm[diverging_isoluminant_cjm_75_c23-v0] _______________

k = 'diverging_isoluminant_cjm_75_c23'
v = <matplotlib.colors.LinearSegmentedColormap object at 0x7f7592dcfa50>

    @pytest.mark.parametrize('k,v', list(cc.cm.items()))
    def test_get_cm(k, v):
        import matplotlib.cm as mcm
>       assert mcm.get_cmap('cet_' + k) is v
E       AssertionError: assert <matplotlib.colors.LinearSegmentedColormap object at 0x7f7591932e50> is <matplotlib.colors.LinearSegmentedColormap object at 0x7f7592dcfa50>
E        +  where <matplotlib.colors.LinearSegmentedColormap object at 0x7f7591932e50> = <function _get_cmap at 0x7f75934dcae0>(('cet_' + 'diverging_isoluminant_cjm_75_c23'))
E        +    where <function _get_cmap at 0x7f75934dcae0> = <module 'matplotlib.cm' from '/usr/lib64/python3.11/site-packages/matplotlib/cm.py'>.get_cmap

../../BUILDROOT/python-colorcet-3.0.0^20211128git39af94a-3.fc38.x86_64/usr/lib/python3.11/site-packages/colorcet/tests/test_matplotlib.py:48: AssertionError

etc. for each parametrization of test_get_cm.

PS, there are also pending deprecation warnings for register_cmap and get_cmap, but these are non-fatal as they are pending.

hoxbro commented 1 year ago

It seems like reasonable changes to implement.

When trying to update the register_cmap, I had some problems with the warning emitted from this line:

https://github.com/matplotlib/matplotlib/blob/9b1fcf67c4228c4a2788af5bcaf0c6fde09a55bf/lib/matplotlib/cm.py#L207

Shouldn't the alternative be: alternative="``matplotlib.colormaps.register(name)``"?

QuLogic commented 1 year ago

Yes, that seems to be a typo.