Skip to content

Commit

Permalink
Merge pull request #760 from girder/more-matplotlib-palettes
Browse files Browse the repository at this point in the history
Work with more more matplotlib palettes.
  • Loading branch information
manthey authored Jan 20, 2022
2 parents 8e62ccf + 49fc1b1 commit 144034e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 5 additions & 4 deletions large_image/tilesource/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions test/test_source_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 144034e

Please sign in to comment.