1
1
.. _cycler_guide :
2
+ .. currentmodule :: matplotlib.cycler
2
3
3
4
==========================
4
5
Style/kwarg cycler Guide
5
6
==========================
6
7
7
- .. currentmodule :: matplotlib.cycler
8
+ `~matplotlib.cycler.Cycler ` API
9
+ ===============================
10
+
11
+ .. autosummary ::
12
+ :toctree: generated/
13
+
14
+ cycler
15
+ Cycler
16
+
17
+
18
+ The public API of `Cycler ` consists of a class
19
+ `~matplotlib.cycler.Cycler ` and a factory function
20
+ `~matplotlib.cycler.cycler `. The class takes care of the composition
21
+ and iteration logic while the function provides a simple interface for
22
+ creating 'base' `Cycler ` objects.
23
+
24
+
25
+ Motivation
26
+ ==========
27
+
8
28
9
29
When plotting more than one line it is common to want to be able to cycle over one
10
30
or more artist styles. For simple cases than can be done with out too much trouble:
@@ -58,23 +78,11 @@ the plotting logic can quickly become very involved. To address this and allow
58
78
cycling over arbitrary ``kwargs `` the `~matplotlib.cycler.Cycler ` class, a composable
59
79
kwarg iterator, was developed.
60
80
81
+ `Cycler ` Usage
82
+ ==============
61
83
62
- `~matplotlib.cycler.Cycler `
63
- ===========================
64
-
65
- The public API of `Cycler ` consists of a class
66
- `~matplotlib.cycler.Cycler ` and a factory function
67
- `~matplotlib.cycler.cycler `. The class takes care of the composition and iteration logic while
68
- the function provides a simple interface for creating 'base' `Cycler ` objects.
69
-
70
- .. autosummary ::
71
- :toctree: generated/
72
-
73
- Cycler
74
- cycler
75
-
76
-
77
- A 'base' `Cycler ` object is some what useful
84
+ A 'base' `Cycler ` object is some what useful and can be used to easily
85
+ cycle over a single style
78
86
79
87
.. plot ::
80
88
:include-source:
@@ -85,13 +93,13 @@ A 'base' `Cycler` object is some what useful
85
93
fig, (ax1, ax2) = plt.subplots(1, 2, tight_layout=True, figsize=(8, 4))
86
94
x = np.arange(10)
87
95
88
- single_cycle = cycler('c', ['r', 'g', 'b'])
96
+ color_cycle = cycler('c', ['r', 'g', 'b'])
89
97
90
- for i, sty in enumerate(single_cycle ):
98
+ for i, sty in enumerate(color_cycle ):
91
99
ax1.plot(x, x*(i+1), **sty)
92
100
93
101
94
- for i, sty in zip(range(1, 10), cycle(single_cycle )):
102
+ for i, sty in zip(range(1, 10), cycle(color_cycle )):
95
103
ax2.plot(x, x*i, **sty)
96
104
97
105
@@ -111,6 +119,16 @@ A 'base' `Cycler` object is some what useful
111
119
len (color_cycle)
112
120
113
121
122
+ fig, (ax1, ax2) = plt.subplots(1 , 2 , tight_layout = True , figsize = (8 , 4 ))
123
+ x = np.arange(10 )
124
+
125
+
126
+ for i, sty in enumerate (color_cycle):
127
+ ax1.plot(x, x* (i+ 1 ), ** sty)
128
+
129
+
130
+
131
+
114
132
115
133
However they are most useful when composed. They can be added
116
134
@@ -157,11 +175,11 @@ complicated cycles to be defined very succinctly
157
175
fig, (ax1, ax2) = plt.subplots(1, 2, tight_layout=True, figsize=(8, 4))
158
176
x = np.arange(10)
159
177
160
- single_cycle = cycler('c', ['r', 'g', 'b'])
178
+ color_cycle = cycler('c', ['r', 'g', 'b'])
161
179
162
- for i, sty in enumerate(single_cycle ):
180
+ for i, sty in enumerate(color_cycle ):
163
181
ax1.plot(x, x*(i+1), **sty)
164
182
165
183
166
- for i, sty in zip(range(1, 10), cycle(single_cycle )):
184
+ for i, sty in zip(range(1, 10), cycle(color_cycle )):
167
185
ax2.plot(x, x*i, **sty)
0 commit comments