Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work with more more matplotlib palettes. #760

Merged
merged 1 commit into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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