本文整理汇总了Python中cycler.cycler方法的典型用法代码示例。如果您正苦于以下问题:Python cycler.cycler方法的具体用法?Python cycler.cycler怎么用?Python cycler.cycler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cycler
的用法示例。
在下文中一共展示了cycler.cycler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _process_keys
# 需要导入模块: import cycler [as 别名]
# 或者: from cycler import cycler [as 别名]
def _process_keys(left, right):
"""
Helper function to compose cycler keys
Parameters
----------
left, right : iterable of dictionaries or None
The cyclers to be composed
Returns
-------
keys : set
The keys in the composition of the two cyclers
"""
l_peek = next(iter(left)) if left is not None else {}
r_peek = next(iter(right)) if right is not None else {}
l_key = set(l_peek.keys())
r_key = set(r_peek.keys())
if l_key & r_key:
raise ValueError("Can not compose overlapping cycles")
return l_key | r_key
示例2: __init__
# 需要导入模块: import cycler [as 别名]
# 或者: from cycler import cycler [as 别名]
def __init__(self, left, right=None, op=None):
"""Semi-private init
Do not use this directly, use `cycler` function instead.
"""
if isinstance(left, Cycler):
self._left = Cycler(left._left, left._right, left._op)
elif left is not None:
# Need to copy the dictionary or else that will be a residual
# mutable that could lead to strange errors
self._left = [copy.copy(v) for v in left]
else:
self._left = None
if isinstance(right, Cycler):
self._right = Cycler(right._left, right._right, right._op)
elif right is not None:
# Need to copy the dictionary or else that will be a residual
# mutable that could lead to strange errors
self._right = [copy.copy(v) for v in right]
else:
self._right = None
self._keys = _process_keys(self._left, self._right)
self._op = op
示例3: _from_iter
# 需要导入模块: import cycler [as 别名]
# 或者: from cycler import cycler [as 别名]
def _from_iter(cls, label, itr):
"""
Class method to create 'base' Cycler objects
that do not have a 'right' or 'op' and for which
the 'left' object is not another Cycler.
Parameters
----------
label : str
The property key.
itr : iterable
Finite length iterable of the property values.
Returns
-------
cycler : Cycler
New 'base' `Cycler`
"""
ret = cls(None)
ret._left = list({label: v} for v in itr)
ret._keys = set([label])
return ret
示例4: simplify
# 需要导入模块: import cycler [as 别名]
# 或者: from cycler import cycler [as 别名]
def simplify(self):
"""Simplify the Cycler
Returned as a composition using only sums (no multiplications)
Returns
-------
simple : Cycler
An equivalent cycler using only summation"""
# TODO: sort out if it is worth the effort to make sure this is
# balanced. Currently it is is
# (((a + b) + c) + d) vs
# ((a + b) + (c + d))
# I would believe that there is some performance implications
trans = self.by_key()
return reduce(add, (_cycler(k, v) for k, v in trans.items()))
示例5: test_constructor
# 需要导入模块: import cycler [as 别名]
# 或者: from cycler import cycler [as 别名]
def test_constructor():
c1 = cycler(c='rgb')
c2 = cycler(ec=c1)
_cycler_helper(c1+c2, 3, ['c', 'ec'], [['r', 'g', 'b']]*2)
c3 = cycler(c=c1)
_cycler_helper(c3+c2, 3, ['c', 'ec'], [['r', 'g', 'b']]*2)
# Using a non-string hashable
c4 = cycler(1, range(3))
_cycler_helper(c4+c1, 3, [1, 'c'], [range(3), ['r', 'g', 'b']])
# addition using cycler()
_cycler_helper(cycler(c='rgb', lw=range(3)),
3, ['c', 'lw'], [list('rgb'), range(3)])
_cycler_helper(cycler(lw=range(3), c='rgb'),
3, ['c', 'lw'], [list('rgb'), range(3)])
# Purposely mixing them
_cycler_helper(cycler(c=range(3), lw=c1),
3, ['c', 'lw'], [range(3), list('rgb')])
示例6: test_repr
# 需要导入模块: import cycler [as 别名]
# 或者: from cycler import cycler [as 别名]
def test_repr():
c = cycler(c='rgb')
# Using an identifier that would be not valid as a kwarg
c2 = cycler('3rd', range(3))
c_sum_rpr = "(cycler('c', ['r', 'g', 'b']) + cycler('3rd', [0, 1, 2]))"
c_prod_rpr = "(cycler('c', ['r', 'g', 'b']) * cycler('3rd', [0, 1, 2]))"
_repr_tester_helper('__repr__', c + c2, c_sum_rpr)
_repr_tester_helper('__repr__', c * c2, c_prod_rpr)
sum_html = "<table><th>'3rd'</th><th>'c'</th><tr><td>0</td><td>'r'</td></tr><tr><td>1</td><td>'g'</td></tr><tr><td>2</td><td>'b'</td></tr></table>"
prod_html = "<table><th>'3rd'</th><th>'c'</th><tr><td>0</td><td>'r'</td></tr><tr><td>1</td><td>'r'</td></tr><tr><td>2</td><td>'r'</td></tr><tr><td>0</td><td>'g'</td></tr><tr><td>1</td><td>'g'</td></tr><tr><td>2</td><td>'g'</td></tr><tr><td>0</td><td>'b'</td></tr><tr><td>1</td><td>'b'</td></tr><tr><td>2</td><td>'b'</td></tr></table>"
_repr_tester_helper('_repr_html_', c + c2, sum_html)
_repr_tester_helper('_repr_html_', c * c2, prod_html)
示例7: simplify
# 需要导入模块: import cycler [as 别名]
# 或者: from cycler import cycler [as 别名]
def simplify(self):
"""Simplify the Cycler
Returned as a composition using only sums (no multiplications)
Returns
-------
simple : Cycler
An equivalent cycler using only summation"""
# TODO: sort out if it is worth the effort to make sure this is
# balanced. Currently it is is
# (((a + b) + c) + d) vs
# ((a + b) + (c + d))
# I would believe that there is some performance implications
trans = self.by_key()
return reduce(add, (_cycler(k, v) for k, v in six.iteritems(trans)))
示例8: generate_errorbar_inputs
# 需要导入模块: import cycler [as 别名]
# 或者: from cycler import cycler [as 别名]
def generate_errorbar_inputs():
base_xy = cycler('x', [np.arange(5)]) + cycler('y', [np.ones((5, ))])
err_cycler = cycler('err', [1,
[1, 1, 1, 1, 1],
[[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]],
[[1]] * 5,
np.ones(5),
np.ones((2, 5)),
np.ones((5, 1)),
None
])
xerr_cy = cycler('xerr', err_cycler)
yerr_cy = cycler('yerr', err_cycler)
empty = ((cycler('x', [[]]) + cycler('y', [[]])) *
cycler('xerr', [[], None]) * cycler('yerr', [[], None]))
xerr_only = base_xy * xerr_cy
yerr_only = base_xy * yerr_cy
both_err = base_xy * yerr_cy * xerr_cy
return [*xerr_only, *yerr_only, *both_err, *empty]
示例9: test_fillcycle_ignore
# 需要导入模块: import cycler [as 别名]
# 或者: from cycler import cycler [as 别名]
def test_fillcycle_ignore():
fig, ax = plt.subplots()
ax.set_prop_cycle(cycler('color', ['r', 'g', 'y']) +
cycler('hatch', ['xx', 'O', '|-']) +
cycler('marker', ['.', '*', 'D']))
xs = np.arange(10)
ys = 0.25 * xs**.5 + 2
# Should not advance the cycler, even though there is an
# unspecified property in the cycler "marker".
# "marker" is not a Polygon property, and should be ignored.
ax.fill(xs, ys, 'r', hatch='xx', label='red, xx')
ys = 0.45 * xs**.5 + 3
# Allow the cycler to advance, but specify some properties
ax.fill(xs, ys, hatch='O', label='red, circle')
ys = 0.65 * xs**.5 + 4
ax.fill(xs, ys, label='green, circle')
ys = 0.85 * xs**.5 + 5
ax.fill(xs, ys, label='yellow, cross')
ax.legend(loc='upper left')
示例10: test_valid_input_forms
# 需要导入模块: import cycler [as 别名]
# 或者: from cycler import cycler [as 别名]
def test_valid_input_forms():
fig, ax = plt.subplots()
# These should not raise an error.
ax.set_prop_cycle(None)
ax.set_prop_cycle(cycler('linewidth', [1, 2]))
ax.set_prop_cycle('color', 'rgywkbcm')
ax.set_prop_cycle('lw', (1, 2))
ax.set_prop_cycle('linewidth', [1, 2])
ax.set_prop_cycle('linewidth', iter([1, 2]))
ax.set_prop_cycle('linewidth', np.array([1, 2]))
ax.set_prop_cycle('color', np.array([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]))
ax.set_prop_cycle('dashes', [[], [13, 2], [8, 3, 1, 3], [None, None]])
ax.set_prop_cycle(lw=[1, 2], color=['k', 'w'], ls=['-', '--'])
ax.set_prop_cycle(lw=np.array([1, 2]),
color=np.array(['k', 'w']),
ls=np.array(['-', '--']))
assert True
示例11: adjust_palette
# 需要导入模块: import cycler [as 别名]
# 或者: from cycler import cycler [as 别名]
def adjust_palette(palette, length):
islist = False
if isinstance(palette, list):
islist = True
if (islist and len(palette) < length) or (
not isinstance(palette, list) and len(palette.by_key()["color"]) < length
):
if length <= 28:
palette = palettes.default_26
elif length <= len(palettes.default_64): # 103 colors
palette = palettes.default_64
else:
palette = ["grey" for _ in range(length)]
logg.info("more than 103 colors would be required, initializing as 'grey'")
return palette if islist else cycler(color=palette)
elif islist:
return palette
elif not isinstance(palette, Cycler):
return cycler(color=palette)
else:
return palette
示例12: test_default_color_cycle
# 需要导入模块: import cycler [as 别名]
# 或者: from cycler import cycler [as 别名]
def test_default_color_cycle(self):
import matplotlib.pyplot as plt
import cycler
colors = list('rgbk')
plt.rcParams['axes.prop_cycle'] = cycler.cycler('color', colors)
df = DataFrame(randn(5, 3))
ax = df.plot()
expected = self._unpack_cycler(plt.rcParams)[:3]
self._check_colors(ax.get_lines(), linecolors=expected)
示例13: test_rcParams_bar_colors
# 需要导入模块: import cycler [as 别名]
# 或者: from cycler import cycler [as 别名]
def test_rcParams_bar_colors(self):
import matplotlib as mpl
color_tuples = [(0.9, 0, 0, 1), (0, 0.9, 0, 1), (0, 0, 0.9, 1)]
with mpl.rc_context(
rc={'axes.prop_cycle': mpl.cycler("color", color_tuples)}):
barplot = pd.DataFrame([[1, 2, 3]]).plot(kind="bar")
assert color_tuples == [c.get_facecolor() for c in barplot.patches]
示例14: change_key
# 需要导入模块: import cycler [as 别名]
# 或者: from cycler import cycler [as 别名]
def change_key(self, old, new):
"""
Change a key in this cycler to a new name.
Modification is performed in-place.
Does nothing if the old key is the same as the new key.
Raises a ValueError if the new key is already a key.
Raises a KeyError if the old key isn't a key.
"""
if old == new:
return
if new in self._keys:
raise ValueError("Can't replace %s with %s, %s is already a key" %
(old, new, new))
if old not in self._keys:
raise KeyError("Can't replace %s with %s, %s is not a key" %
(old, new, old))
self._keys.remove(old)
self._keys.add(new)
if self._right is not None and old in self._right.keys:
self._right.change_key(old, new)
# self._left should always be non-None
# if self._keys is non-empty.
elif isinstance(self._left, Cycler):
self._left.change_key(old, new)
else:
# It should be completely safe at this point to
# assume that the old key can be found in each
# iteration.
self._left = [{new: entry[old]} for entry in self._left]
示例15: __repr__
# 需要导入模块: import cycler [as 别名]
# 或者: from cycler import cycler [as 别名]
def __repr__(self):
op_map = {zip: '+', product: '*'}
if self._right is None:
lab = self.keys.pop()
itr = list(v[lab] for v in self)
return "cycler({lab!r}, {itr!r})".format(lab=lab, itr=itr)
else:
op = op_map.get(self._op, '?')
msg = "({left!r} {op} {right!r})"
return msg.format(left=self._left, op=op, right=self._right)