Python Examples

The following are 2 code examples for showing how to use These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may want to check out the right sidebar which shows the related API usage.

You may also want to check out all available functions/classes of the module , or try the search function .

Example 1
Project: allesfitter   Author: MNGuenther   File:    License: MIT License 6 votes vote down vote up
def get_cmap( cmap, name=None, n=256 ):
    """ in: a name "Blues" "BuGn_r" ... of a builtin cmap (case-sensitive)
        or a filename, np.loadtxt() n x 3 or 4  ints 0..255 or floats 0..1
        or a cmap already
        or a numpy array.
        or in IPython,<tab>
    if isinstance( cmap, colors.Colormap ):
        return cmap
    if isinstance( cmap, str ):
        if cmap in cm.cmap_d:
            return pl.get_cmap( cmap )  # "Blues" ...
        A = np.loadtxt( cmap, delimiter=None )  # None: white space
        name = name or cmap.split("/")[-1] .split(".")[0]  # .../xx.csv -> xx
        A = cmap  # numpy array or array-like
    return array_cmap( A, name, n=n ) 
Example 2
Project: holoviews   Author: holoviz   File:    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def _list_cmaps(provider=None, records=False):
    List available colormaps by combining matplotlib, bokeh, and
    colorcet colormaps or palettes if available. May also be
    narrowed down to a particular provider or list of providers.
    if provider is None:
        provider = providers
    elif isinstance(provider, basestring):
        if provider not in providers:
            raise ValueError('Colormap provider %r not recognized, must '
                             'be one of %r' % (provider, providers))
        provider = [provider]

    cmaps = []

    def info(provider,names):
        return [CMapInfo(name=n,provider=provider,category=None,source=None,bg=None) for n in names] \
               if records else list(names)

    if 'matplotlib' in provider:
            import as cm
            cmaps += info('matplotlib',
                          [cmap for cmap in cm.cmap_d if not
                           (cmap.startswith('cet_') or      # duplicates list below
                            cmap.startswith('Vega') or      # deprecated in matplotlib=2.1
                            cmap.startswith('spectral') )]) # deprecated in matplotlib=2.1
    if 'bokeh' in provider:
            from bokeh import palettes
            cmaps += info('bokeh', palettes.all_palettes)
            cmaps += info('bokeh', [p+'_r' for p in palettes.all_palettes])
    if 'colorcet' in provider:
            from colorcet import palette_n, glasbey_hv
            cet_maps = palette_n.copy()
            cet_maps['glasbey_hv'] = glasbey_hv # Add special hv-specific map
            cmaps += info('colorcet', cet_maps) 
            cmaps += info('colorcet', [p+'_r' for p in cet_maps])
    return sorted(unique_iterator(cmaps))