Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a03b63d

Browse files
authored
Merge pull request matplotlib#11084 from timhoffm/backport-of-pr-10899
Backport PR matplotlib#10899: Update cycler docstrings and favor kwarg over two…
2 parents ba9714c + 213a0db commit a03b63d

File tree

7 files changed

+45
-34
lines changed

7 files changed

+45
-34
lines changed

doc/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ def _check_deps():
9696
'python': ('https://docs.python.org/3', None),
9797
'numpy': ('https://docs.scipy.org/doc/numpy/', None),
9898
'scipy': ('https://docs.scipy.org/doc/scipy/reference/', None),
99-
'pandas': ('https://pandas.pydata.org/pandas-docs/stable', None)
99+
'pandas': ('https://pandas.pydata.org/pandas-docs/stable', None),
100+
'cycler': ('https://matplotlib.org/cycler', None),
100101
}
101102

102103
explicit_order_folders = [

examples/api/filled_step.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ def stack_hist(ax, stacked_data, sty_cycle, bottoms=None,
181181

182182
# set up style cycles
183183
color_cycle = cycler(facecolor=plt.rcParams['axes.prop_cycle'][:4])
184-
label_cycle = cycler('label', ['set {n}'.format(n=n) for n in range(4)])
185-
hatch_cycle = cycler('hatch', ['/', '*', '+', '|'])
184+
label_cycle = cycler(label=['set {n}'.format(n=n) for n in range(4)])
185+
hatch_cycle = cycler(hatch=['/', '*', '+', '|'])
186186

187187
# Fixing random state for reproducibility
188188
np.random.seed(19680801)

examples/color/color_cycler.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@
2424

2525
# 1. Setting prop cycle on default rc parameter
2626
plt.rc('lines', linewidth=4)
27-
plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']) +
28-
cycler('linestyle', ['-', '--', ':', '-.'])))
27+
plt.rc('axes', prop_cycle=(cycler(color=['r', 'g', 'b', 'y']) +
28+
cycler(linestyle=['-', '--', ':', '-.'])))
2929
fig, (ax0, ax1) = plt.subplots(nrows=2)
3030
ax0.plot(yy)
3131
ax0.set_title('Set default color cycle to rgby')
3232

3333
# 2. Define prop cycle for single set of axes
34-
ax1.set_prop_cycle(cycler('color', ['c', 'm', 'y', 'k']) +
35-
cycler('lw', [1, 2, 3, 4]))
34+
# For the most general use-case, you can provide a cycler to
35+
# `.set_prop_cycle`.
36+
# Here, we use the convenient shortcut that we can alternatively pass
37+
# one or more properties as keyword arguements. This creates and sets
38+
# a cycler iterating simultaneously over all properties.
39+
ax1.set_prop_cycle(color=['c', 'm', 'y', 'k'], lw=[1, 2, 3, 4])
3640
ax1.plot(yy)
3741
ax1.set_title('Set axes color cycle to cmyk')
3842

lib/matplotlib/axes/_base.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,16 +1186,22 @@ def set_prop_cycle(self, *args, **kwargs):
11861186
Call signatures::
11871187
11881188
set_prop_cycle(cycler)
1189-
set_prop_cycle(label, values)
11901189
set_prop_cycle(label=values[, label2=values2[, ...]])
1190+
set_prop_cycle(label, values)
11911191
1192-
Form 1 simply sets given `Cycler` object.
1192+
Form 1 sets given `~cycler.Cycler` object.
11931193
1194-
Form 2 creates and sets a `Cycler` from a label and an iterable.
1194+
Form 2 creates a `~cycler.Cycler` which cycles over one or more
1195+
properties simultaneously and set it as the property cycle of the
1196+
axes. If multiple properties are given, their value lists must have
1197+
the same length. This is just a shortcut for explicitly creating a
1198+
cycler and passing it to the function, i.e. it's short for
1199+
``set_prop_cycle(cycler(label=values label2=values2, ...))``.
11951200
1196-
Form 3 composes and sets a `Cycler` as an inner product of the
1197-
pairs of keyword arguments. In other words, all of the
1198-
iterables are cycled simultaneously, as if through zip().
1201+
Form 3 creates a `~cycler.Cycler` for a single property and set it
1202+
as the property cycle of the axes. This form exists for compatibility
1203+
with the original `cycler.cycler` interface. Its use is discouraged
1204+
in favor of the kwarg form, i.e. ``set_prop_cycle(label=values)``.
11991205
12001206
Parameters
12011207
----------
@@ -1216,8 +1222,7 @@ def set_prop_cycle(self, *args, **kwargs):
12161222
--------
12171223
Setting the property cycle for a single property:
12181224
1219-
>>> ax.set_prop_cycle(color=['red', 'green', 'blue']) # or
1220-
>>> ax.set_prop_cycle('color', ['red', 'green', 'blue'])
1225+
>>> ax.set_prop_cycle(color=['red', 'green', 'blue'])
12211226
12221227
Setting the property cycle for simultaneously cycling over multiple
12231228
properties (e.g. red circle, green plus, blue cross):
@@ -1228,7 +1233,9 @@ def set_prop_cycle(self, *args, **kwargs):
12281233
See Also
12291234
--------
12301235
matplotlib.rcsetup.cycler
1231-
Convenience function for creating your own cyclers.
1236+
Convenience function for creating validated cyclers for properties.
1237+
cycler.cycler
1238+
The original function for creating unvalidated cyclers.
12321239
12331240
"""
12341241
if args and kwargs:

lib/matplotlib/rcsetup.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -719,22 +719,24 @@ def validate_hatch(s):
719719

720720
def cycler(*args, **kwargs):
721721
"""
722-
Creates a :class:`cycler.Cycler` object much like :func:`cycler.cycler`,
722+
Creates a `~cycler.Cycler` object much like :func:`cycler.cycler`,
723723
but includes input validation.
724724
725725
Call signatures::
726726
727727
cycler(cycler)
728-
cycler(label, values)
729728
cycler(label=values[, label2=values2[, ...]])
729+
cycler(label, values)
730730
731-
Form 1 simply copies a given `Cycler` object.
731+
Form 1 copies a given `~cycler.Cycler` object.
732732
733-
Form 2 creates a `Cycler` from a label and an iterable.
733+
Form 2 creates a `~cycler.Cycler` which cycles over one or more
734+
properties simultaneously. If multiple properties are given, their
735+
value lists must have the same length.
734736
735-
Form 3 composes a `Cycler` as an inner product of the
736-
pairs of keyword arguments. In other words, all of the
737-
iterables are cycled simultaneously, as if through zip().
737+
Form 3 creates a `~cycler.Cycler` for a single property. This form
738+
exists for compatibility with the original cycler. Its use is
739+
discouraged in favor of the kwarg form, i.e. ``cycler(label=values)``.
738740
739741
Parameters
740742
----------
@@ -753,14 +755,13 @@ def cycler(*args, **kwargs):
753755
Returns
754756
-------
755757
cycler : Cycler
756-
New :class:`cycler.Cycler` for the given properties
758+
A new :class:`~cycler.Cycler` for the given properties.
757759
758760
Examples
759761
--------
760762
Creating a cycler for a single property:
761763
762-
>>> c = cycler(color=['red', 'green', 'blue']) # or
763-
>>> c = cycler('color', ['red', 'green', 'blue'])
764+
>>> c = cycler(color=['red', 'green', 'blue'])
764765
765766
Creating a cycler for simultaneously cycling over multiple properties
766767
(e.g. red circle, green plus, blue cross):

lib/matplotlib/stackplot.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
import six
1313
from six.moves import xrange
14-
15-
from cycler import cycler
1614
import numpy as np
1715

1816
__all__ = ['stackplot']
@@ -69,7 +67,7 @@ def stackplot(axes, x, *args, **kwargs):
6967

7068
colors = kwargs.pop('colors', None)
7169
if colors is not None:
72-
axes.set_prop_cycle(cycler('color', colors))
70+
axes.set_prop_cycle(color=colors)
7371

7472
baseline = kwargs.pop('baseline', 'zero')
7573
# Assume data passed has not been 'stacked', so stack it here.

tutorials/intermediate/color_cycle.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
# cycler and a linestyle cycler by adding (``+``) two ``cycler``'s together.
4040
# See the bottom of this tutorial for more information about combining
4141
# different cyclers.
42-
default_cycler = cycler('color', ['r', 'g', 'b', 'y']) \
43-
+ cycler('linestyle', ['-', '--', ':', '-.'])
42+
default_cycler = (cycler(color=['r', 'g', 'b', 'y']) +
43+
cycler(linestyle=['-', '--', ':', '-.']))
4444

4545
plt.rc('lines', linewidth=4)
4646
plt.rc('axes', prop_cycle=default_cycler)
@@ -52,8 +52,8 @@
5252
# which will only set the ``prop_cycle`` for this :mod:`matplotlib.axes.Axes`
5353
# instance. We'll use a second ``cycler`` that combines a color cycler and a
5454
# linewidth cycler.
55-
custom_cycler = cycler('color', ['c', 'm', 'y', 'k']) \
56-
+ cycler('lw', [1, 2, 3, 4])
55+
custom_cycler = (cycler(color=['c', 'm', 'y', 'k']) +
56+
cycler(lw=[1, 2, 3, 4]))
5757

5858
fig, (ax0, ax1) = plt.subplots(nrows=2)
5959
ax0.plot(yy)
@@ -76,7 +76,7 @@
7676
#
7777
# ..code-block:: python
7878
#
79-
# axes.prop_cycle : cycler('color', 'bgrcmyk')
79+
# axes.prop_cycle : cycler(color='bgrcmyk')
8080
#
8181
# Cycling through multiple properties
8282
# -----------------------------------

0 commit comments

Comments
 (0)