Skip to content

Commit 0710775

Browse files
committed
DOC: document how to get 'persistent' cycles
closes #4
1 parent 30a8b94 commit 0710775

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

doc/source/index.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,34 @@ We can use `Cycler` instances to cycle over one or more ``kwarg`` to
245245
ax2.plot(x, x*(i+1), **sty)
246246
247247

248+
Persistent Cycles
249+
-----------------
250+
251+
It can be useful to associate a given label with a style via
252+
dictionary lookup and to dynamically generate that mapping. This
253+
can easily be accomplished using a `~collections.defaultdict`
254+
255+
.. ipython:: python
256+
257+
from cycler import cycler as cy
258+
from collections import defaultdict
259+
260+
cyl = cy('c', 'rgb') + cy('lw', range(1, 4))
261+
262+
To get a finite set of styles
263+
264+
.. ipython:: python
265+
266+
finite_cy_iter = iter(cyl)
267+
dd_finite = defaultdict(lambda : next(finite_cy_iter))
268+
269+
or repeating
270+
271+
.. ipython:: python
272+
273+
loop_cy_iter = cyl()
274+
dd_loop = defaultdict(lambda : next(loop_cy_iter))
275+
248276
Exceptions
249277
----------
250278

0 commit comments

Comments
 (0)