| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0d0eb39 commit 3a5a5a4
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -87,7 +87,8 @@ def _check_deps(): | |||
| 87 | 87 | 'python': ('https://docs.python.org/3', None), | |
| 88 | 88 | 'numpy': ('https://docs.scipy.org/doc/numpy/', None), | |
| 89 | 89 | 'scipy': ('https://docs.scipy.org/doc/scipy/reference/', None), | |
| 90 | - 'pandas': ('https://pandas.pydata.org/pandas-docs/stable', None) | ||
| 90 | + 'pandas': ('https://pandas.pydata.org/pandas-docs/stable', None), | ||
| 91 | + 'cycler': ('https://matplotlib.org/cycler', None), | ||
| 91 | 92 | } | |
| 92 | 93 | ||
| 93 | 94 | explicit_order_folders = [ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -180,8 +180,8 @@ def stack_hist(ax, stacked_data, sty_cycle, bottoms=None, | |||
| 180 | 180 | ||
| 181 | 181 | # set up style cycles | |
| 182 | 182 | color_cycle = cycler(facecolor=plt.rcParams['axes.prop_cycle'][:4]) | |
| 183 | - label_cycle = cycler('label', ['set {n}'.format(n=n) for n in range(4)]) | ||
| 184 | - hatch_cycle = cycler('hatch', ['/', '*', '+', '|']) | ||
| 183 | + label_cycle = cycler(label=['set {n}'.format(n=n) for n in range(4)]) | ||
| 184 | + hatch_cycle = cycler(hatch=['/', '*', '+', '|']) | ||
| 185 | 185 | ||
| 186 | 186 | # Fixing random state for reproducibility | |
| 187 | 187 | np.random.seed(19680801) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,15 +24,19 @@ | |||
| 24 | 24 | ||
| 25 | 25 | # 1. Setting prop cycle on default rc parameter | |
| 26 | 26 | 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=['-', '--', ':', '-.']))) | ||
| 29 | 29 | fig, (ax0, ax1) = plt.subplots(nrows=2) | |
| 30 | 30 | ax0.plot(yy) | |
| 31 | 31 | ax0.set_title('Set default color cycle to rgby') | |
| 32 | 32 | ||
| 33 | 33 | # 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]) | ||
| 36 | 40 | ax1.plot(yy) | |
| 37 | 41 | ax1.set_title('Set axes color cycle to cmyk') | |
| 38 | 42 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,13 +41,8 @@ | |||
| 41 | 41 | '#17becf', | |
| 42 | 42 | '#1a55FF'] | |
| 43 | 43 | ||
| 44 | - # Create two different cyclers to use with axes.prop_cycle | ||
| 45 | - markevery_cycler = cycler(markevery=cases) | ||
| 46 | - color_cycler = cycler('color', colors) | ||
| 47 | - | ||
| 48 | - # Configure rcParams axes.prop_cycle with custom cycler | ||
| 49 | - custom_cycler = color_cycler + markevery_cycler | ||
| 50 | - mpl.rcParams['axes.prop_cycle'] = custom_cycler | ||
| 44 | + # Configure rcParams axes.prop_cycle to simultaneously cycle cases and colors. | ||
| 45 | + mpl.rcParams['axes.prop_cycle'] = cycler(markevery=cases, color=colors) | ||
| 51 | 46 | ||
| 52 | 47 | # Create data points and offsets | |
| 53 | 48 | x = np.linspace(0, 2 * np.pi) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1158,16 +1158,22 @@ def set_prop_cycle(self, *args, **kwargs): | |||
| 1158 | 1158 | Call signatures:: | |
| 1159 | 1159 | ||
| 1160 | 1160 | set_prop_cycle(cycler) | |
| 1161 | - set_prop_cycle(label, values) | ||
| 1162 | 1161 | set_prop_cycle(label=values[, label2=values2[, ...]]) | |
| 1162 | + set_prop_cycle(label, values) | ||
| 1163 | 1163 | ||
| 1164 | - Form 1 simply sets given `Cycler` object. | ||
| 1164 | + Form 1 sets given `~cycler.Cycler` object. | ||
| 1165 | 1165 | ||
| 1166 | - Form 2 creates and sets a `Cycler` from a label and an iterable. | ||
| 1166 | + Form 2 creates a `~cycler.Cycler` which cycles over one or more | ||
| 1167 | + properties simultaneously and set it as the property cycle of the | ||
| 1168 | + axes. If multiple properties are given, their value lists must have | ||
| 1169 | + the same length. This is just a shortcut for explicitly creating a | ||
| 1170 | + cycler and passing it to the function, i.e. it's short for | ||
| 1171 | + ``set_prop_cycle(cycler(label=values label2=values2, ...))``. | ||
| 1167 | 1172 | ||
| 1168 | - Form 3 composes and sets a `Cycler` as an inner product of the | ||
| 1169 | - pairs of keyword arguments. In other words, all of the | ||
| 1170 | - iterables are cycled simultaneously, as if through zip(). | ||
| 1173 | + Form 3 creates a `~cycler.Cycler` for a single property and set it | ||
| 1174 | + as the property cycle of the axes. This form exists for compatibility | ||
| 1175 | + with the original `cycler.cycler` interface. Its use is discouraged | ||
| 1176 | + in favor of the kwarg form, i.e. ``set_prop_cycle(label=values)``. | ||
| 1171 | 1177 | ||
| 1172 | 1178 | Parameters | |
| 1173 | 1179 | ---------- | |
@@ -1188,8 +1194,7 @@ def set_prop_cycle(self, *args, **kwargs): | |||
| 1188 | 1194 | -------- | |
| 1189 | 1195 | Setting the property cycle for a single property: | |
| 1190 | 1196 | ||
| 1191 | - >>> ax.set_prop_cycle(color=['red', 'green', 'blue']) # or | ||
| 1192 | - >>> ax.set_prop_cycle('color', ['red', 'green', 'blue']) | ||
| 1197 | + >>> ax.set_prop_cycle(color=['red', 'green', 'blue']) | ||
| 1193 | 1198 | ||
| 1194 | 1199 | Setting the property cycle for simultaneously cycling over multiple | |
| 1195 | 1200 | properties (e.g. red circle, green plus, blue cross): | |
@@ -1200,7 +1205,9 @@ def set_prop_cycle(self, *args, **kwargs): | |||
| 1200 | 1205 | See Also | |
| 1201 | 1206 | -------- | |
| 1202 | 1207 | matplotlib.rcsetup.cycler | |
| 1203 | - Convenience function for creating your own cyclers. | ||
| 1208 | + Convenience function for creating validated cyclers for properties. | ||
| 1209 | + cycler.cycler | ||
| 1210 | + The original function for creating unvalidated cyclers. | ||
| 1204 | 1211 | ||
| 1205 | 1212 | """ | |
| 1206 | 1213 | if args and kwargs: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -744,22 +744,24 @@ def validate_hatch(s): | |||
| 744 | 744 | ||
| 745 | 745 | def cycler(*args, **kwargs): | |
| 746 | 746 | """ | |
| 747 | - Creates a :class:`cycler.Cycler` object much like :func:`cycler.cycler`, | ||
| 747 | + Creates a `~cycler.Cycler` object much like :func:`cycler.cycler`, | ||
| 748 | 748 | but includes input validation. | |
| 749 | 749 | ||
| 750 | 750 | Call signatures:: | |
| 751 | 751 | ||
| 752 | 752 | cycler(cycler) | |
| 753 | - cycler(label, values) | ||
| 754 | 753 | cycler(label=values[, label2=values2[, ...]]) | |
| 754 | + cycler(label, values) | ||
| 755 | 755 | ||
| 756 | - Form 1 simply copies a given `Cycler` object. | ||
| 756 | + Form 1 copies a given `~cycler.Cycler` object. | ||
| 757 | 757 | ||
| 758 | - Form 2 creates a `Cycler` from a label and an iterable. | ||
| 758 | + Form 2 creates a `~cycler.Cycler` which cycles over one or more | ||
| 759 | + properties simultaneously. If multiple properties are given, their | ||
| 760 | + value lists must have the same length. | ||
| 759 | 761 | ||
| 760 | - Form 3 composes a `Cycler` as an inner product of the | ||
| 761 | - pairs of keyword arguments. In other words, all of the | ||
| 762 | - iterables are cycled simultaneously, as if through zip(). | ||
| 762 | + Form 3 creates a `~cycler.Cycler` for a single property. This form | ||
| 763 | + exists for compatibility with the original cycler. Its use is | ||
| 764 | + discouraged in favor of the kwarg form, i.e. ``cycler(label=values)``. | ||
| 763 | 765 | ||
| 764 | 766 | Parameters | |
| 765 | 767 | ---------- | |
@@ -778,14 +780,13 @@ def cycler(*args, **kwargs): | |||
| 778 | 780 | Returns | |
| 779 | 781 | ------- | |
| 780 | 782 | cycler : Cycler | |
| 781 | - New :class:`cycler.Cycler` for the given properties | ||
| 783 | + A new :class:`~cycler.Cycler` for the given properties. | ||
| 782 | 784 | ||
| 783 | 785 | Examples | |
| 784 | 786 | -------- | |
| 785 | 787 | Creating a cycler for a single property: | |
| 786 | 788 | ||
| 787 | - >>> c = cycler(color=['red', 'green', 'blue']) # or | ||
| 788 | - >>> c = cycler('color', ['red', 'green', 'blue']) | ||
| 789 | + >>> c = cycler(color=['red', 'green', 'blue']) | ||
| 789 | 790 | ||
| 790 | 791 | Creating a cycler for simultaneously cycling over multiple properties | |
| 791 | 792 | (e.g. red circle, green plus, blue cross): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,6 @@ | |||
| 9 | 9 | from __future__ import (absolute_import, division, print_function, | |
| 10 | 10 | unicode_literals) | |
| 11 | 11 | ||
| 12 | - from cycler import cycler | ||
| 13 | 12 | import numpy as np | |
| 14 | 13 | ||
| 15 | 14 | __all__ = ['stackplot'] | |
@@ -66,7 +65,7 @@ def stackplot(axes, x, *args, **kwargs): | |||
| 66 | 65 | ||
| 67 | 66 | colors = kwargs.pop('colors', None) | |
| 68 | 67 | if colors is not None: | |
| 69 | - axes.set_prop_cycle(cycler('color', colors)) | ||
| 68 | + axes.set_prop_cycle(color=colors) | ||
| 70 | 69 | ||
| 71 | 70 | baseline = kwargs.pop('baseline', 'zero') | |
| 72 | 71 | # Assume data passed has not been 'stacked', so stack it here. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,8 +39,8 @@ | |||
| 39 | 39 | # cycler and a linestyle cycler by adding (``+``) two ``cycler``'s together. | |
| 40 | 40 | # See the bottom of this tutorial for more information about combining | |
| 41 | 41 | # 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=['-', '--', ':', '-.'])) | ||
| 44 | 44 | ||
| 45 | 45 | plt.rc('lines', linewidth=4) | |
| 46 | 46 | plt.rc('axes', prop_cycle=default_cycler) | |
@@ -52,8 +52,8 @@ | |||
| 52 | 52 | # which will only set the ``prop_cycle`` for this :mod:`matplotlib.axes.Axes` | |
| 53 | 53 | # instance. We'll use a second ``cycler`` that combines a color cycler and a | |
| 54 | 54 | # 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])) | ||
| 57 | 57 | ||
| 58 | 58 | fig, (ax0, ax1) = plt.subplots(nrows=2) | |
| 59 | 59 | ax0.plot(yy) | |
@@ -76,7 +76,7 @@ | |||
| 76 | 76 | # | |
| 77 | 77 | # ..code-block:: python | |
| 78 | 78 | # | |
| 79 | - # axes.prop_cycle : cycler('color', 'bgrcmyk') | ||
| 79 | + # axes.prop_cycle : cycler(color='bgrcmyk') | ||
| 80 | 80 | # | |
| 81 | 81 | # Cycling through multiple properties | |
| 82 | 82 | # ----------------------------------- | |
| Back | FazBrowse Home | New Git URL |
0 commit comments