Python cycler.cycler() Examples
The following are 30
code examples of cycler.cycler().
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 also want to check out all available functions/classes of the module
cycler
, or try the search function
.
Example #1
Source File: cycler.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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
Example #2
Source File: test_cycles.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
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')
Example #3
Source File: utils.py From scvelo with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #4
Source File: test_cycler.py From cycler with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #5
Source File: test_cycles.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #6
Source File: test_axes.py From coffeegrindsize with MIT License | 6 votes |
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]
Example #7
Source File: cycler.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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
Example #8
Source File: test_cycler.py From cycler with BSD 3-Clause "New" or "Revised" License | 6 votes |
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')])
Example #9
Source File: cycler.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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
Example #10
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
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]
Example #11
Source File: test_cycles.py From coffeegrindsize with MIT License | 6 votes |
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')
Example #12
Source File: test_cycles.py From coffeegrindsize with MIT License | 6 votes |
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
Example #13
Source File: cycler.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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)))
Example #14
Source File: cycler.py From cycler with BSD 3-Clause "New" or "Revised" License | 6 votes |
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()))
Example #15
Source File: cycler.py From CogAlg with MIT License | 6 votes |
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
Example #16
Source File: cycler.py From cycler with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #17
Source File: cycler.py From CogAlg with MIT License | 6 votes |
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
Example #18
Source File: cycler.py From cycler with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #19
Source File: cycler.py From cycler with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #20
Source File: test_cycles.py From coffeegrindsize with MIT License | 5 votes |
def test_marker_cycle(): fig, ax = plt.subplots() ax.set_prop_cycle(cycler('c', ['r', 'g', 'y']) + cycler('marker', ['.', '*', 'x'])) xs = np.arange(10) ys = 0.25 * xs + 2 ax.plot(xs, ys, label='red dot', lw=4, ms=16) ys = 0.45 * xs + 3 ax.plot(xs, ys, label='green star', lw=4, ms=16) ys = 0.65 * xs + 4 ax.plot(xs, ys, label='yellow x', lw=4, ms=16) ys = 0.85 * xs + 5 ax.plot(xs, ys, label='red2 dot', lw=4, ms=16) ax.legend(loc='upper left') fig, ax = plt.subplots() # Test keyword arguments, numpy arrays, and generic iterators ax.set_prop_cycle(c=np.array(['r', 'g', 'y']), marker=iter(['.', '*', 'x'])) xs = np.arange(10) ys = 0.25 * xs + 2 ax.plot(xs, ys, label='red dot', lw=4, ms=16) ys = 0.45 * xs + 3 ax.plot(xs, ys, label='green star', lw=4, ms=16) ys = 0.65 * xs + 4 ax.plot(xs, ys, label='yellow x', lw=4, ms=16) ys = 0.85 * xs + 5 ax.plot(xs, ys, label='red2 dot', lw=4, ms=16) ax.legend(loc='upper left')
Example #21
Source File: test_cycles.py From coffeegrindsize with MIT License | 5 votes |
def test_colorcycle_basic(): fig, ax = plt.subplots() ax.set_prop_cycle(cycler('color', ['r', 'g', 'y'])) xs = np.arange(10) ys = 0.25 * xs + 2 ax.plot(xs, ys, label='red', lw=4) ys = 0.45 * xs + 3 ax.plot(xs, ys, label='green', lw=4) ys = 0.65 * xs + 4 ax.plot(xs, ys, label='yellow', lw=4) ys = 0.85 * xs + 5 ax.plot(xs, ys, label='red2', lw=4) ax.legend(loc='upper left')
Example #22
Source File: test_frame.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
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)
Example #23
Source File: test_cycles.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_invalid_input_forms(): fig, ax = plt.subplots() with pytest.raises((TypeError, ValueError)): ax.set_prop_cycle(1) with pytest.raises((TypeError, ValueError)): ax.set_prop_cycle([1, 2]) with pytest.raises((TypeError, ValueError)): ax.set_prop_cycle('color', 'fish') with pytest.raises((TypeError, ValueError)): ax.set_prop_cycle('linewidth', 1) with pytest.raises((TypeError, ValueError)): ax.set_prop_cycle('linewidth', {'1': 1, '2': 2}) with pytest.raises((TypeError, ValueError)): ax.set_prop_cycle(linewidth=1, color='r') with pytest.raises((TypeError, ValueError)): ax.set_prop_cycle('foobar', [1, 2]) with pytest.raises((TypeError, ValueError)): ax.set_prop_cycle(foobar=[1, 2]) with pytest.raises((TypeError, ValueError)): ax.set_prop_cycle(cycler(foobar=[1, 2])) with pytest.raises(ValueError): ax.set_prop_cycle(cycler(color='rgb', c='cmy'))
Example #24
Source File: cycler.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _cycler(label, itr): """ Create a new `Cycler` object from a property name and iterable of values. Parameters ---------- label : hashable The property key. itr : iterable Finite length iterable of the property values. Returns ------- cycler : Cycler New `Cycler` for the given property """ if isinstance(itr, Cycler): keys = itr.keys if len(keys) != 1: msg = "Can not create Cycler from a multi-property Cycler" raise ValueError(msg) lab = keys.pop() # Doesn't need to be a new list because # _from_iter() will be creating that new list anyway. itr = (v[lab] for v in itr) return Cycler._from_iter(label, itr)
Example #25
Source File: test_cycles.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_fillcycle_basic(): fig, ax = plt.subplots() ax.set_prop_cycle(cycler('c', ['r', 'g', 'y']) + cycler('hatch', ['xx', 'O', '|-']) + cycler('linestyle', ['-', '--', ':'])) xs = np.arange(10) ys = 0.25 * xs**.5 + 2 ax.fill(xs, ys, label='red, xx', linewidth=3) ys = 0.45 * xs**.5 + 3 ax.fill(xs, ys, label='green, circle', linewidth=3) ys = 0.65 * xs**.5 + 4 ax.fill(xs, ys, label='yellow, cross', linewidth=3) ys = 0.85 * xs**.5 + 5 ax.fill(xs, ys, label='red2, xx', linewidth=3) ax.legend(loc='upper left')
Example #26
Source File: test_cycles.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_marker_cycle(): fig, ax = plt.subplots() ax.set_prop_cycle(cycler('c', ['r', 'g', 'y']) + cycler('marker', ['.', '*', 'x'])) xs = np.arange(10) ys = 0.25 * xs + 2 ax.plot(xs, ys, label='red dot', lw=4, ms=16) ys = 0.45 * xs + 3 ax.plot(xs, ys, label='green star', lw=4, ms=16) ys = 0.65 * xs + 4 ax.plot(xs, ys, label='yellow x', lw=4, ms=16) ys = 0.85 * xs + 5 ax.plot(xs, ys, label='red2 dot', lw=4, ms=16) ax.legend(loc='upper left') fig, ax = plt.subplots() # Test keyword arguments, numpy arrays, and generic iterators ax.set_prop_cycle(c=np.array(['r', 'g', 'y']), marker=iter(['.', '*', 'x'])) xs = np.arange(10) ys = 0.25 * xs + 2 ax.plot(xs, ys, label='red dot', lw=4, ms=16) ys = 0.45 * xs + 3 ax.plot(xs, ys, label='green star', lw=4, ms=16) ys = 0.65 * xs + 4 ax.plot(xs, ys, label='yellow x', lw=4, ms=16) ys = 0.85 * xs + 5 ax.plot(xs, ys, label='red2 dot', lw=4, ms=16) ax.legend(loc='upper left')
Example #27
Source File: test_cycles.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_colorcycle_basic(): fig, ax = plt.subplots() ax.set_prop_cycle(cycler('color', ['r', 'g', 'y'])) xs = np.arange(10) ys = 0.25 * xs + 2 ax.plot(xs, ys, label='red', lw=4) ys = 0.45 * xs + 3 ax.plot(xs, ys, label='green', lw=4) ys = 0.65 * xs + 4 ax.plot(xs, ys, label='yellow', lw=4) ys = 0.85 * xs + 5 ax.plot(xs, ys, label='red2', lw=4) ax.legend(loc='upper left')
Example #28
Source File: test_lines.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_lw_scaling(): th = np.linspace(0, 32) fig, ax = plt.subplots() lins_styles = ['dashed', 'dotted', 'dashdot'] cy = cycler(matplotlib.rcParams['axes.prop_cycle']) for j, (ls, sty) in enumerate(zip(lins_styles, cy)): for lw in np.linspace(.5, 10, 10): ax.plot(th, j*np.ones(50) + .1 * lw, linestyle=ls, lw=lw, **sty)
Example #29
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_errorbar_with_prop_cycle(): _cycle = cycler(ls=['--', ':'], marker=['s', 's'], mfc=['k', 'w']) plt.rc("axes", prop_cycle=_cycle) fig, ax = plt.subplots() ax.errorbar(x=[2, 4, 10], y=[3, 2, 4], yerr=0.5) ax.errorbar(x=[2, 4, 10], y=[6, 4, 2], yerr=0.5)
Example #30
Source File: cycler.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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)