当前位置: 首页>>代码示例>>Python>>正文


Python colors.from_levels_and_colors方法代码示例

本文整理汇总了Python中matplotlib.colors.from_levels_and_colors方法的典型用法代码示例。如果您正苦于以下问题:Python colors.from_levels_and_colors方法的具体用法?Python colors.from_levels_and_colors怎么用?Python colors.from_levels_and_colors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.colors的用法示例。


在下文中一共展示了colors.from_levels_and_colors方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _addusepaaqi

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import from_levels_and_colors [as 别名]
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) 
开发者ID:barronh,项目名称:pseudonetcdf,代码行数:23,代码来源:colors.py

示例2: test_cmap_and_norm_from_levels_and_colors

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import from_levels_and_colors [as 别名]
def test_cmap_and_norm_from_levels_and_colors():
    data = np.linspace(-2, 4, 49).reshape(7, 7)
    levels = [-1, 2, 2.5, 3]
    colors = ['red', 'green', 'blue', 'yellow', 'black']
    extend = 'both'
    cmap, norm = mcolors.from_levels_and_colors(levels, colors, extend=extend)

    ax = plt.axes()
    m = plt.pcolormesh(data, cmap=cmap, norm=norm)
    plt.colorbar(m)

    # Hide the axes labels (but not the colorbar ones, as they are useful)
    for lab in ax.get_xticklabels() + ax.get_yticklabels():
        lab.set_visible(False) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:16,代码来源:test_colors.py

示例3: test_cmap_and_norm_from_levels_and_colors

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import from_levels_and_colors [as 别名]
def test_cmap_and_norm_from_levels_and_colors():
    data = np.linspace(-2, 4, 49).reshape(7, 7)
    levels = [-1, 2, 2.5, 3]
    colors = ['red', 'green', 'blue', 'yellow', 'black']
    extend = 'both'
    cmap, norm = mcolors.from_levels_and_colors(levels, colors, extend=extend)

    ax = plt.axes()
    m = plt.pcolormesh(data, cmap=cmap, norm=norm)
    plt.colorbar(m)

    # Hide the axes labels (but not the colorbar ones, as they are useful)
    ax.tick_params(labelleft=False, labelbottom=False) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:15,代码来源:test_colors.py

示例4: _one_color_cmap

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import from_levels_and_colors [as 别名]
def _one_color_cmap(color):
    """Generate a colormap with only one color.

    Useful for imshow.

    Parameters:
        color (str):
            Color.

    Returns:
        `matplotlib.cm <http://matplotlib.org/api/cm_api.html>`_ (colormap)
        object
    """
    cmap, ig = from_levels_and_colors(levels=(0, 1), colors=(color,))
    return cmap 
开发者ID:sdss,项目名称:marvin,代码行数:17,代码来源:colorbar.py

示例5: test_cmap_and_norm_from_levels_and_colors2

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import from_levels_and_colors [as 别名]
def test_cmap_and_norm_from_levels_and_colors2():
    levels = [-1, 2, 2.5, 3]
    colors = ['red', (0, 1, 0), 'blue', (0.5, 0.5, 0.5), (0.0, 0.0, 0.0, 1.0)]
    clr = mcolors.colorConverter.to_rgba_array(colors)
    bad = (0.1, 0.1, 0.1, 0.1)
    no_color = (0.0, 0.0, 0.0, 0.0)
    masked_value = 'masked_value'

    # Define the test values which are of interest.
    # Note: levels are lev[i] <= v < lev[i+1]
    tests = [('both', None, {-2: clr[0],
                             -1: clr[1],
                             2: clr[2],
                             2.25: clr[2],
                             3: clr[4],
                             3.5: clr[4],
                             masked_value: bad}),

             ('min', -1, {-2: clr[0],
                          -1: clr[1],
                          2: clr[2],
                          2.25: clr[2],
                          3: no_color,
                          3.5: no_color,
                          masked_value: bad}),

             ('max', -1, {-2: no_color,
                          -1: clr[0],
                          2: clr[1],
                          2.25: clr[1],
                          3: clr[3],
                          3.5: clr[3],
                          masked_value: bad}),

             ('neither', -2, {-2: no_color,
                              -1: clr[0],
                              2: clr[1],
                              2.25: clr[1],
                              3: no_color,
                              3.5: no_color,
                              masked_value: bad}),
             ]

    for extend, i1, cases in tests:
        cmap, norm = mcolors.from_levels_and_colors(levels, colors[0:i1],
                                                    extend=extend)
        cmap.set_bad(bad)
        for d_val, expected_color in cases.items():
            if d_val == masked_value:
                d_val = np.ma.array([1], mask=True)
            else:
                d_val = [d_val]
            assert_array_equal(expected_color, cmap(norm(d_val))[0],
                               'Wih extend={0!r} and data '
                               'value={1!r}'.format(extend, d_val))

    assert_raises(ValueError, mcolors.from_levels_and_colors, levels, colors) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:59,代码来源:test_colors.py

示例6: test_cmap_and_norm_from_levels_and_colors2

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import from_levels_and_colors [as 别名]
def test_cmap_and_norm_from_levels_and_colors2():
    levels = [-1, 2, 2.5, 3]
    colors = ['red', (0, 1, 0), 'blue', (0.5, 0.5, 0.5), (0.0, 0.0, 0.0, 1.0)]
    clr = mcolors.to_rgba_array(colors)
    bad = (0.1, 0.1, 0.1, 0.1)
    no_color = (0.0, 0.0, 0.0, 0.0)
    masked_value = 'masked_value'

    # Define the test values which are of interest.
    # Note: levels are lev[i] <= v < lev[i+1]
    tests = [('both', None, {-2: clr[0],
                             -1: clr[1],
                             2: clr[2],
                             2.25: clr[2],
                             3: clr[4],
                             3.5: clr[4],
                             masked_value: bad}),

             ('min', -1, {-2: clr[0],
                          -1: clr[1],
                          2: clr[2],
                          2.25: clr[2],
                          3: no_color,
                          3.5: no_color,
                          masked_value: bad}),

             ('max', -1, {-2: no_color,
                          -1: clr[0],
                          2: clr[1],
                          2.25: clr[1],
                          3: clr[3],
                          3.5: clr[3],
                          masked_value: bad}),

             ('neither', -2, {-2: no_color,
                              -1: clr[0],
                              2: clr[1],
                              2.25: clr[1],
                              3: no_color,
                              3.5: no_color,
                              masked_value: bad}),
             ]

    for extend, i1, cases in tests:
        cmap, norm = mcolors.from_levels_and_colors(levels, colors[0:i1],
                                                    extend=extend)
        cmap.set_bad(bad)
        for d_val, expected_color in cases.items():
            if d_val == masked_value:
                d_val = np.ma.array([1], mask=True)
            else:
                d_val = [d_val]
            assert_array_equal(expected_color, cmap(norm(d_val))[0],
                               'Wih extend={0!r} and data '
                               'value={1!r}'.format(extend, d_val))

    with pytest.raises(ValueError):
        mcolors.from_levels_and_colors(levels, colors) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:60,代码来源:test_colors.py


注:本文中的matplotlib.colors.from_levels_and_colors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。