本文整理汇总了Python中matplotlib.colors.to_rgba_array函数的典型用法代码示例。如果您正苦于以下问题:Python to_rgba_array函数的具体用法?Python to_rgba_array怎么用?Python to_rgba_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_rgba_array函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: set_alpha
def set_alpha(self, alpha):
"""
Set the alpha transparencies of the collection.
Parameters
----------
alpha : float or None
"""
if alpha is not None:
try:
float(alpha)
except TypeError:
raise TypeError('alpha must be a float or None')
artist.Artist.set_alpha(self, alpha)
try:
self._facecolors = mcolors.to_rgba_array(
self._facecolors3d, self._alpha)
except (AttributeError, TypeError, IndexError):
pass
try:
self._edgecolors = mcolors.to_rgba_array(
self._edgecolors3d, self._alpha)
except (AttributeError, TypeError, IndexError):
pass
self.stale = True
开发者ID:dopplershift,项目名称:matplotlib,代码行数:25,代码来源:art3d.py
示例2: test_conversions_masked
def test_conversions_masked():
x1 = np.ma.array(['k', 'b'], mask=[True, False])
x2 = np.ma.array([[0, 0, 0, 1], [0, 0, 1, 1]])
x2[0] = np.ma.masked
assert mcolors.to_rgba(x1[0]) == (0, 0, 0, 0)
assert_array_equal(mcolors.to_rgba_array(x1),
[[0, 0, 0, 0], [0, 0, 1, 1]])
assert_array_equal(mcolors.to_rgba_array(x2), mcolors.to_rgba_array(x1))
开发者ID:QuLogic,项目名称:matplotlib,代码行数:8,代码来源:test_colors.py
示例3: set_alpha
def set_alpha(self, alpha):
# docstring inherited
artist.Artist.set_alpha(self, alpha)
try:
self._facecolors3d = mcolors.to_rgba_array(
self._facecolors3d, self._alpha)
except (AttributeError, TypeError, IndexError):
pass
try:
self._edgecolors = mcolors.to_rgba_array(
self._edgecolors3d, self._alpha)
except (AttributeError, TypeError, IndexError):
pass
self.stale = True
开发者ID:QuLogic,项目名称:matplotlib,代码行数:14,代码来源:art3d.py
示例4: test_to_rgba_array_single_str
def test_to_rgba_array_single_str():
# single color name is valid
assert_array_equal(mcolors.to_rgba_array("red"), [(1, 0, 0, 1)])
# single char color sequence is deprecated
with pytest.warns(cbook.MatplotlibDeprecationWarning,
match="Using a string of single character colors as a "
"color sequence is deprecated"):
array = mcolors.to_rgba_array("rgb")
assert_array_equal(array, [(1, 0, 0, 1), (0, 0.5, 0, 1), (0, 0, 1, 1)])
with pytest.raises(ValueError,
match="neither a valid single color nor a color "
"sequence"):
mcolors.to_rgba_array("rgbx")
开发者ID:QuLogic,项目名称:matplotlib,代码行数:15,代码来源:test_colors.py
示例5: test_conversions
def test_conversions():
# to_rgba_array("none") returns a (0, 4) array.
assert_array_equal(mcolors.to_rgba_array("none"), np.zeros((0, 4)))
# a list of grayscale levels, not a single color.
assert_array_equal(
mcolors.to_rgba_array([".2", ".5", ".8"]),
np.vstack([mcolors.to_rgba(c) for c in [".2", ".5", ".8"]]))
# alpha is properly set.
assert mcolors.to_rgba((1, 1, 1), .5) == (1, 1, 1, .5)
assert mcolors.to_rgba(".1", .5) == (.1, .1, .1, .5)
# builtin round differs between py2 and py3.
assert mcolors.to_hex((.7, .7, .7)) == "#b2b2b2"
# hex roundtrip.
hex_color = "#1234abcd"
assert mcolors.to_hex(mcolors.to_rgba(hex_color), keep_alpha=True) == \
hex_color
开发者ID:dstansby,项目名称:matplotlib,代码行数:16,代码来源:test_colors.py
示例6: do_3d_projection
def do_3d_projection(self, renderer):
xs, ys, zs = self._offsets3d
vxs, vys, vzs, vis = proj3d.proj_transform_clip(xs, ys, zs, renderer.M)
fcs = (zalpha(self._facecolor3d, vzs) if self._depthshade else
self._facecolor3d)
fcs = mcolors.to_rgba_array(fcs, self._alpha)
self.set_facecolors(fcs)
ecs = (zalpha(self._edgecolor3d, vzs) if self._depthshade else
self._edgecolor3d)
ecs = mcolors.to_rgba_array(ecs, self._alpha)
self.set_edgecolors(ecs)
PathCollection.set_offsets(self, np.column_stack([vxs, vys]))
return np.min(vzs) if vzs.size else np.nan
开发者ID:dopplershift,项目名称:matplotlib,代码行数:16,代码来源:art3d.py
示例7: first_color
def first_color(colors):
if colors is None:
return None
colors = mcolors.to_rgba_array(colors)
if len(colors):
return colors[0]
else:
return "none"
开发者ID:JIE2016G,项目名称:matplotlib,代码行数:8,代码来源:legend_handler.py
示例8: test_rgba
def test_rgba(self):
a_masked = np.ma.array([1, 2, 3, np.nan, np.nan, 6],
mask=[False, False, True, True, False, False])
a_rgba = mcolors.to_rgba_array(['r', 'g', 'b', 'c', 'm', 'y'])
actual = delete_masked_points(a_masked, a_rgba)
ind = [0, 1, 5]
assert_array_equal(actual[0], a_masked[ind].compressed())
assert_array_equal(actual[1], a_rgba[ind])
开发者ID:QuLogic,项目名称:matplotlib,代码行数:8,代码来源:test_cbook.py
示例9: test_cmap_and_norm_from_levels_and_colors2
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:dstansby,项目名称:matplotlib,代码行数:58,代码来源:test_colors.py
示例10: test_conversions
def test_conversions():
# to_rgba_array("none") returns a (0, 4) array.
assert_array_equal(mcolors.to_rgba_array("none"), np.zeros((0, 4)))
# alpha is properly set.
assert_equal(mcolors.to_rgba((1, 1, 1), .5), (1, 1, 1, .5))
# builtin round differs between py2 and py3.
assert_equal(mcolors.to_hex((.7, .7, .7)), "#b2b2b2")
# hex roundtrip.
hex_color = "#1234abcd"
assert_equal(mcolors.to_hex(mcolors.to_rgba(hex_color), keep_alpha=True),
hex_color)
开发者ID:717524640,项目名称:matplotlib,代码行数:11,代码来源:test_colors.py
示例11: _zalpha
def _zalpha(colors, zs):
"""Modify the alphas of the color list according to depth."""
# FIXME: This only works well if the points for *zs* are well-spaced
# in all three dimensions. Otherwise, at certain orientations,
# the min and max zs are very close together.
# Should really normalize against the viewing depth.
if len(zs) == 0:
return np.zeros((0, 4))
norm = Normalize(min(zs), max(zs))
sats = 1 - norm(zs) * 0.7
rgba = np.broadcast_to(mcolors.to_rgba_array(colors), (len(zs), 4))
return np.column_stack([rgba[:, :3], rgba[:, 3] * sats])
开发者ID:QuLogic,项目名称:matplotlib,代码行数:12,代码来源:art3d.py
示例12: setup_method
def setup_method(self):
self.mask1 = [False, False, True, True, False, False]
self.arr0 = np.arange(1.0, 7.0)
self.arr1 = [1, 2, 3, np.nan, np.nan, 6]
self.arr2 = np.array(self.arr1)
self.arr3 = np.ma.array(self.arr2, mask=self.mask1)
self.arr_s = ['a', 'b', 'c', 'd', 'e', 'f']
self.arr_s2 = np.array(self.arr_s)
self.arr_dt = [datetime(2008, 1, 1), datetime(2008, 1, 2),
datetime(2008, 1, 3), datetime(2008, 1, 4),
datetime(2008, 1, 5), datetime(2008, 1, 6)]
self.arr_dt2 = np.array(self.arr_dt)
self.arr_colors = ['r', 'g', 'b', 'c', 'm', 'y']
self.arr_rgba = mcolors.to_rgba_array(self.arr_colors)
开发者ID:HubertHolin,项目名称:matplotlib,代码行数:14,代码来源:test_cbook.py
示例13: setUp
def setUp(self):
self.mask1 = [False, False, True, True, False, False]
self.arr0 = np.arange(1.0, 7.0)
self.arr1 = [1, 2, 3, np.nan, np.nan, 6]
self.arr2 = np.array(self.arr1)
self.arr3 = np.ma.array(self.arr2, mask=self.mask1)
self.arr_s = ["a", "b", "c", "d", "e", "f"]
self.arr_s2 = np.array(self.arr_s)
self.arr_dt = [
datetime(2008, 1, 1),
datetime(2008, 1, 2),
datetime(2008, 1, 3),
datetime(2008, 1, 4),
datetime(2008, 1, 5),
datetime(2008, 1, 6),
]
self.arr_dt2 = np.array(self.arr_dt)
self.arr_colors = ["r", "g", "b", "c", "m", "y"]
self.arr_rgba = mcolors.to_rgba_array(self.arr_colors)
开发者ID:QuLogic,项目名称:matplotlib,代码行数:19,代码来源:test_cbook.py
示例14: _is_light
def _is_light(color):
"""Determines if a color (or each of a sequence of colors) is light (as
opposed to dark). Based on ITU BT.601 luminance formula (see
https://stackoverflow.com/a/596241)."""
rgbaArr = colors.to_rgba_array(color)
return rgbaArr[:,:3].dot((.299, .587, .114)) > .5
开发者ID:ipython,项目名称:ipykernel,代码行数:6,代码来源:backend_inline.py
示例15: get_colors
def get_colors(c, num):
"""Stretch the color argument to provide the required number *num*."""
return np.broadcast_to(
mcolors.to_rgba_array(c) if len(c) else [0, 0, 0, 0],
(num, 4))
开发者ID:magnunor,项目名称:matplotlib,代码行数:5,代码来源:art3d.py
示例16: print
import matplotlib.colors as colors
import matplotlib.cm as cm
print(colors.to_hex("r"))
print(colors.to_rgba_array("r"))
print(colors.to_rgba("r"))
print(colors.to_rgba([1, 1, 1]))
print(cm.get_cmap("Blues").N)
print(cm.get_cmap("Blues")(0))
print(cm.get_cmap("Blues")(10))
# print(dir(cm.get_cmap("Blues")# <matplotlib.colors.LinearSegmentedColormap object at 0x7fa6149b5da0>
开发者ID:podhmo,项目名称:individual-sandbox,代码行数:13,代码来源:00color.py
注:本文中的matplotlib.colors.to_rgba_array函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论