From 49fc1b1834c78995f17e3ca4fa0c06d9d82584de Mon Sep 17 00:00:00 2001 From: David Manthey Date: Thu, 20 Jan 2022 12:21:19 -0500 Subject: [PATCH] Work with more more matplotlib palettes. Fixes #759. --- CHANGELOG.md | 1 + large_image/tilesource/utilities.py | 9 +++++---- test/test_source_base.py | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce3156061..96a3c5127 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Improvements - Expand user paths ([#746](../../pull/746)) +- Work with more matplotlib palettes ([#760](../../pull/760)) ### Changes - Use importlib rather than pkg_resources internally ([#747](../../pull/747)) diff --git a/large_image/tilesource/utilities.py b/large_image/tilesource/utilities.py index 6a69a2a49..ad82d64a0 100644 --- a/large_image/tilesource/utilities.py +++ b/large_image/tilesource/utilities.py @@ -460,10 +460,11 @@ def getPaletteColors(value): try: import matplotlib - palette = ( - ['#0000', matplotlib.colors.to_hex(value)] - if value in matplotlib.colors.get_named_colors_mapping() - else matplotlib.cm.get_cmap(value).colors) + if value in matplotlib.colors.get_named_colors_mapping(): + palette = ['#0000', matplotlib.colors.to_hex(value)] + else: + cmap = matplotlib.cm.get_cmap(value) + palette = [matplotlib.colors.to_hex(cmap(i)) for i in range(cmap.N)] except (ImportError, ValueError, AttributeError): pass if palette is None: diff --git a/test/test_source_base.py b/test/test_source_base.py index 5eb34db7c..7609feeea 100644 --- a/test/test_source_base.py +++ b/test/test_source_base.py @@ -164,6 +164,7 @@ def testIsGeospatial(filename, isgeo): 'viridis', 'matplotlib.Plasma_6', [(0.5, 0.5, 0.5), (0.1, 0.1, 0.1, 0.1), 'xkcd:blue'], + 'coolwarm', ]) def testGoodGetPaletteColors(palette): large_image.tilesource.utilities.getPaletteColors(palette)