本文整理汇总了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)
示例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)
示例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)
示例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
示例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)
示例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)