From c6341ee758a44eccf87fa1db0dc57f16d1e441f4 Mon Sep 17 00:00:00 2001 From: endolith Date: Tue, 6 Aug 2024 21:22:27 -0400 Subject: [PATCH] Fix ValueError from repeated import ehtplot.color If a script importing this module is run more than once, it produces ValueError: A colormap named "afmhot_10u" is already registered. Now it overwrites the existing colormaps instead, and fixes #5. --- ehtplot/color/core.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ehtplot/color/core.py b/ehtplot/color/core.py index a0cd927..85479be 100644 --- a/ehtplot/color/core.py +++ b/ehtplot/color/core.py @@ -38,9 +38,9 @@ def register(name=None, cmap=None, path=None): if cmap is None: cmap = ListedColormap(load_ctab(name, path=path)) - # Register the colormap - register_cmap(name=name, cmap=cmap) + # Register the colormap, overwriting if it already exists + register_cmap(name=name, cmap=cmap, override_builtin=True) # Register the reversed colormap register_cmap(name=name + ("_r" if unmodified(name) else "r"), - cmap=cmap.reversed()) + cmap=cmap.reversed(), override_builtin=True)