question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: A colormap named "cet_gray" is already registered

See original GitHub issue

Software version info

colorcet 3.0.1 arviz 0.12.1 python 3.10/8 matplotlib 3.6.0/1 afaik introduced with recent colorcet/matplotlib release

Description of expected behavior and the observed behavior

When multiple libraries use mpl.colormaps.register(cmap, name=cmap_name) with the same cmap_name, a ValueError: A colormap named "cet_gray" is already registered. is raised. This happens e.g. for colorcet + arviz, both of which define cet_gray (see here for arviz, here for colorcet).

Arviz appears here to emulate the colorcet color.

Is this an issue/responsibility of colorcet/arviz/…?

Complete, minimal, self-contained example code that reproduces the issue

import arviz
import colorcet

or

import colorcet
import arviz

This prohibits the use of both simultaneously.

Stacktrace

Traceback (most recent call last):
 File "<string>", line 1, in <module>
 File "/home/yannik/env/env/lib/python3.10/site-packages/arviz/__init__.py", line 320, in <module>
   _mpl_cm("gray", _linear_grey_10_95_c0)
 File "/home/yannik/env/env/lib/python3.10/site-packages/arviz/__init__.py", line 317, in _mpl_cm
   register_cmap("cet_" + name, cmap=cmap)
 File "/home/yannik/env/env/lib/python3.10/site-packages/matplotlib/_api/deprecation.py", line 200, in wrapper
   return func(*args, **kwargs)
 File "/home/yannik/env/env/lib/python3.10/site-packages/matplotlib/cm.py", line 248, in register_cmap
   _colormaps.register(cmap, name=name, force=override_builtin)
 File "/home/yannik/env/env/lib/python3.10/site-packages/matplotlib/cm.py", line 149, in register
   raise ValueError(
ValueError: A colormap named "cet_gray" is already registered.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
OriolAbrilcommented, Oct 12, 2022

Maybe we can add a check and only register the cmap if colorcet is not installed? (so that both import orders work as opposed to checking if the cmap is registered and requiring arviz to be imported second) cc @aloctavodia

0reactions
ColCarrollcommented, Oct 13, 2022

Sounds like they are suggesting something similar to you, @OriolAbril ! https://github.com/holoviz/colorcet/issues/96#issuecomment-1276576516

Read more comments on GitHub >

github_iconTop Results From Across the Web

supporting Matplotlib 3.4 and beyond, registering external ...
Bug report Bug summary Since matplotlib 3.4.0, registering a colormap with an existing name results in an error (this is the reason why...
Read more >
Register Matplotlib Colormap - python - Stack Overflow
Your colormap gets registered. plt.cm only contains the built-in colormaps, not the registered ones. To get the colormap use ...
Read more >
matplotlib.cm — Matplotlib 3.6.2 documentation
If False, a ValueError is raised if trying to overwrite an already registered name. True supports overwriting registered colormaps other than the builtin ......
Read more >
Source code for proplot.styletools
Try using @timer on # register functions, turns out worst is colormap one at 0.1 ... raise ValueError( 'Data mapping points must have...
Read more >
Based on a Select widget update a second Select widget, then ...
I am trying to put together an app where user can: decide between colormap collections (for example between Matplotlib and Colorcet) using a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found