@@ -81,53 +81,64 @@ kwarg iterator, was developed.
81
81
`Cycler ` Usage
82
82
==============
83
83
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
85
85
cycle over a single style
86
86
87
- .. plot ::
88
- :include-source:
87
+ .. ipython :: python
89
88
89
+ from __future__ import print_function
90
90
from matplotlib.cycler import cycler
91
- from itertools import cycle
92
91
93
- fig, (ax1, ax2) = plt.subplots(1, 2, tight_layout=True, figsize=(8, 4))
94
- x = np.arange(10)
95
92
96
- color_cycle = cycler('c', ['r', 'g', 'b'])
93
+ color_cycle = cycler(' c' , [' r' , ' g' , ' b' , ' purple ' ])
97
94
98
- for i, sty in enumerate(color_cycle):
99
- ax1.plot(x, x*(i+1), **sty)
95
+ color_cycle
100
96
97
+ for v in color_cycle:
98
+ print (v)
101
99
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
104
102
103
+ Cycles can be sliced with `silce ` objects
105
104
106
105
.. ipython :: python
107
106
108
- from __future__ import print_function
109
- from matplotlib.cycler import cycler
107
+ color_cycle[::- 1 ]
108
+ color_cycle[:2 ]
109
+ color_cycle[1 :]
110
110
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
111
113
112
- color_cycle = cycler( ' c ' , [ ' r ' , ' g ' , ' b ' ])
114
+ .. ipython :: python
113
115
114
- color_cycle
116
+ color_cycle * 2
117
+ 2 * color_cycle[:2 ]
115
118
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
118
122
119
- len (color_cycle)
123
+ .. ipython :: python
120
124
125
+ lw_cycle = cycler(' lw' , range (1 , 5 ))
126
+ ls_cycle = cycler(' ls' , [' -' , ' --' ])
121
127
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
124
132
133
+ color_cycle + ls_cycle* 2
125
134
126
- for i, sty in enumerate (color_cycle):
127
- ax1.plot(x, x* (i+ 1 ), ** sty)
135
+ color_color + ls_cycle
128
136
137
+ and any pair of `Cycler ` can be multiplied
129
138
139
+ .. ipython :: python
130
140
141
+ ls_cycle * color_cycle
131
142
132
143
133
144
However they are most useful when composed. They can be added
@@ -166,6 +177,25 @@ complicated cycles to be defined very succinctly
166
177
.. ipython :: python
167
178
168
179
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
+
169
199
.. plot ::
170
200
:include-source:
171
201
0 commit comments