Python matplotlib.cm.register_cmap() Examples

The following are 5 code examples for showing how to use matplotlib.cm.register_cmap(). 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 matplotlib.cm , or try the search function .

Example 1
Project: pseudonetcdf   Author: barronh   File: colors.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def _addusepaaqi():
    aqicolors = ['green', 'yellow', 'orange', 'red', 'purple', 'maroon']
    aqic = aqicolors
    bounds_colors = {}
    bounds_colors[('O3', 'mda8', 'ppbv')] = ([0, 55, 71, 86, 106, 200],
                                             aqic[:5] + ['black'], 'max')
    bounds_colors[('O3', 'mda8', 'ppmv')] = ([0, 0.055, 0.071, 0.086,
                                              0.106, 0.0200],
                                             aqic[:5] + ['black'], 'max')
    bounds_colors[('O3', 'mda1', 'ppbv')] = ([125, 165, 205, 405, 604],
                                             ['white'] + aqic[2:] + ['black'],
                                             'both')
    pmb = [0, 12.1, 35.5, 55.5, 150.5, 250.5, 500.4]
    pmc = aqic + ['black']
    bounds_colors[('PM25', 'a24', 'micrograms/m**3')] = (pmb, pmc, 'max')
    for key, (bnds, colors, extend) in bounds_colors.items():
        print(key)
        name = '_'.join(('usepa', 'aqi',) + key)
        cmap, norm = from_levels_and_colors(bnds, colors, extend=extend)
        register_cmap(name=name, cmap=cmap)
        register_norm(name=name, norm=norm) 
Example 2
Project: xcube   Author: dcs4cop   File: test_cmaps.py    License: MIT License 5 votes vote down vote up
def test_get_cmaps_registers_snap_color(self):
        ensure_cmaps_loaded()
        cmap_name = os.path.join(os.path.dirname(__file__), 'chl_DeM2_200.cpd')
        cmap = _get_custom_colormap(cmap_name)
        cm.register_cmap(cmap=cmap)
        self.assertTrue((type(cmap) is LinearSegmentedColormap) or (type(cmap) is ListedColormap)) 
Example 3
Project: xcube   Author: dcs4cop   File: test_cmaps.py    License: MIT License 5 votes vote down vote up
def test_get_cmaps_registers_ivalid_snap_color(self):
        ensure_cmaps_loaded()
        cmap_name = os.path.join(os.path.dirname(__file__), 'chl_DeM2_200_invalid_for_testing.cpd')
        with self.assertRaises(ValueError):
            cmap = _get_custom_colormap(cmap_name)
            cm.register_cmap(cmap=cmap) 
Example 4
Project: xcube   Author: dcs4cop   File: test_cmaps.py    License: MIT License 5 votes vote down vote up
def test_get_cmaps_registers_nonexisting_snap_color(self):
        ensure_cmaps_loaded()
        cmap_name = 'test/webapi/im/chl_DeM2_200_not_existing.cpd'
        with self.assertRaises(ValueError):
            cmap = _get_custom_colormap(cmap_name)
            cm.register_cmap(cmap=cmap) 
Example 5
Project: cate   Author: CCI-Tools   File: cmap_lc.py    License: MIT License 4 votes vote down vote up
def register_lc_color_map():
    lc_color_mappings = [
        (0, dict(r=0, g=0, b=0)),
        (10, dict(r=255, g=255, b=100)),
        (11, dict(r=255, g=255, b=100)),
        (12, dict(r=255, g=255, b=0)),
        (20, dict(r=170, g=240, b=240)),
        (30, dict(r=220, g=240, b=100)),
        (40, dict(r=200, g=200, b=100)),
        (50, dict(r=0, g=100, b=0)),
        (60, dict(r=0, g=160, b=0)),
        (61, dict(r=0, g=160, b=0)),
        (62, dict(r=170, g=200, b=0)),
        (70, dict(r=0, g=60, b=0)),
        (71, dict(r=0, g=60, b=0)),
        (72, dict(r=0, g=80, b=0)),
        (80, dict(r=40, g=80, b=0)),
        (81, dict(r=40, g=80, b=0)),
        (82, dict(r=40, g=100, b=0)),
        (90, dict(r=120, g=130, b=0)),
        (100, dict(r=140, g=160, b=0)),
        (110, dict(r=190, g=150, b=0)),
        (120, dict(r=150, g=100, b=0)),
        (121, dict(r=120, g=75, b=0)),
        (122, dict(r=150, g=100, b=0)),
        (130, dict(r=255, g=180, b=50)),
        (140, dict(r=255, g=220, b=210)),
        (150, dict(r=255, g=235, b=175)),
        (151, dict(r=255, g=205, b=120)),
        (152, dict(r=255, g=210, b=120)),
        (153, dict(r=255, g=235, b=175)),
        (160, dict(r=0, g=120, b=190)),
        (170, dict(r=0, g=150, b=120)),
        (180, dict(r=0, g=220, b=130)),
        (190, dict(r=195, g=20, b=0)),
        (200, dict(r=255, g=245, b=215)),
        (201, dict(r=220, g=220, b=220)),
        (202, dict(r=255, g=245, b=215)),
        (210, dict(r=0, g=70, b=200)),
        (220, dict(r=255, g=255, b=255)),
    ]

    classes = {lc: color for lc, color in lc_color_mappings}

    invalid_rgba = (0, 0, 0, 0.5)
    class_0_rgba = (0, 0, 0, 0)

    rgba_list = []
    num_entries = 256
    last_rgba = invalid_rgba
    for i in range(num_entries):
        color = classes.get(i)
        if color:
            last_rgba = (color['r'] / 255, color['g'] / 255, color['b'] / 255, 1.0)
        rgba_list.append(last_rgba)
    rgba_list[0] = class_0_rgba

    cmap = matplotlib.colors.ListedColormap(rgba_list, name=LAND_COVER_CCI_CMAP, N=num_entries)
    cm.register_cmap(cmap=cmap)