Skip to content

Commit 3b905c1

Browse files
committed
DOC/WIP
1 parent 58610f4 commit 3b905c1

File tree

1 file changed

+52
-22
lines changed

1 file changed

+52
-22
lines changed

doc/users/cycler.rst

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,53 +81,64 @@ kwarg iterator, was developed.
8181
`Cycler` Usage
8282
==============
8383

84-
A 'base' `Cycler` object is some what useful and can be used to easily
84+
A 'base' `Cycler` object is somewhat useful and can be used to easily
8585
cycle over a single style
8686

87-
.. plot::
88-
:include-source:
87+
.. ipython:: python
8988
89+
from __future__ import print_function
9090
from matplotlib.cycler import cycler
91-
from itertools import cycle
9291
93-
fig, (ax1, ax2) = plt.subplots(1, 2, tight_layout=True, figsize=(8, 4))
94-
x = np.arange(10)
9592
96-
color_cycle = cycler('c', ['r', 'g', 'b'])
93+
color_cycle = cycler('c', ['r', 'g', 'b', 'purple'])
9794
98-
for i, sty in enumerate(color_cycle):
99-
ax1.plot(x, x*(i+1), **sty)
95+
color_cycle
10096
97+
for v in color_cycle:
98+
print(v)
10199
102-
for i, sty in zip(range(1, 10), cycle(color_cycle)):
103-
ax2.plot(x, x*i, **sty)
100+
len(color_cycle)
101+
color_cycle.keys
104102
103+
Cycles can be sliced with `silce` objects
105104

106105
.. ipython:: python
107106
108-
from __future__ import print_function
109-
from matplotlib.cycler import cycler
107+
color_cycle[::-1]
108+
color_cycle[:2]
109+
color_cycle[1:]
110110
111+
to return a sub-set of the cycle as a new `Cycler`. They can also be multiplied
112+
by scalars to make fixed length periodic cycles
111113

112-
color_cycle = cycler('c', ['r', 'g', 'b'])
114+
.. ipython:: python
113115
114-
color_cycle
116+
color_cycle * 2
117+
2 * color_cycle[:2]
115118
116-
for v in color_cycle:
117-
print(v)
119+
but the real power of `Cycler` objects is when composing them. Equal
120+
length `Cycler` with different keys can be added to get the 'inner'
121+
product of two cycles
118122

119-
len(color_cycle)
123+
.. ipython:: python
120124
125+
lw_cycle = cycler('lw', range(1, 5))
126+
ls_cycle = cycler('ls', ['-', '--'])
121127
122-
fig, (ax1, ax2) = plt.subplots(1, 2, tight_layout=True, figsize=(8, 4))
123-
x = np.arange(10)
128+
wc = lw_cycle + color_cycle
129+
wc
130+
len(wc)
131+
wc.keys
124132
133+
color_cycle + ls_cycle*2
125134
126-
for i, sty in enumerate(color_cycle):
127-
ax1.plot(x, x*(i+1), **sty)
135+
color_color + ls_cycle
128136
137+
and any pair of `Cycler` can be multiplied
129138

139+
.. ipython:: python
130140
141+
ls_cycle * color_cycle
131142
132143
133144
However they are most useful when composed. They can be added
@@ -166,6 +177,25 @@ complicated cycles to be defined very succinctly
166177
.. ipython:: python
167178
168179
180+
.. plot::
181+
:include-source:
182+
183+
from matplotlib.cycler import cycler
184+
from itertools import cycle
185+
186+
fig, (ax1, ax2) = plt.subplots(1, 2, tight_layout=True, figsize=(8, 4))
187+
x = np.arange(10)
188+
189+
color_cycle = cycler('c', ['r', 'g', 'b'])
190+
191+
for i, sty in enumerate(color_cycle):
192+
ax1.plot(x, x*(i+1), **sty)
193+
194+
195+
for i, sty in zip(range(1, 10), cycle(color_cycle)):
196+
ax2.plot(x, x*i, **sty)
197+
198+
169199
.. plot::
170200
:include-source:
171201

0 commit comments

Comments
 (0)