Skip to content

Add named_palettes #4

@jbednar

Description

@jbednar

Widget-based applications very often need to provide a list of colormaps/palettes for the user to select via a widget. The complete list of colorcet palettes is unwieldy for such a purpose, and the names are obscure, but there is a subset that has readable names that is probably also the most commonly needed set. Should add some code like the following to easily provide a list of useful colormaps, with a useful default at the front:

def odict_to_front(odict,key):
    """Given an OrderedDict, move the item with the given key to the front."""
    front_item = [(key,odict[key])]
    other_items = [(k,v) for k,v in odict.items() if k is not key]
    return OrderedDict(front_item+other_items)

from colorcet import palette
default_palette = "fire"
named_palettes = {k:p for k,p in palette.items() if not '_' in k}
sorted_palettes = OrderedDict(sorted(named_palettes.items()))
typical_palettes = odict_to_front(sorted_palettes,default_palette)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions