From 9c61a9deb023b6613322730b44a1e1ff0f425430 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 29 May 2016 15:52:30 -0400 Subject: [PATCH 1/4] MNT: remove unreachable code The validation on the rcParams means that `rcParams['axes.prop_cycle']` can never be None. --- lib/matplotlib/axes/_base.py | 3 --- lib/matplotlib/colors.py | 4 ---- 2 files changed, 7 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 15c45b122f5f..3bb856b1ad6f 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -164,9 +164,6 @@ def __setstate__(self, state): def set_prop_cycle(self, *args, **kwargs): if not (args or kwargs) or (len(args) == 1 and args[0] is None): prop_cycler = rcParams['axes.prop_cycle'] - if prop_cycler is None and 'axes.color_cycle' in rcParams: - clist = rcParams['axes.color_cycle'] - prop_cycler = cycler('color', clist) else: prop_cycler = cycler(*args, **kwargs) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 8a2efaea3f50..a5ab755cb422 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -126,11 +126,7 @@ def to_rgba(c, alpha=None): # Special-case nth color syntax because it should not be cached. if _is_nth_color(c): from matplotlib import rcParams - from matplotlib.rcsetup import cycler prop_cycler = rcParams['axes.prop_cycle'] - if prop_cycler is None and 'axes.color_cycle' in rcParams: - clist = rcParams['axes.color_cycle'] - prop_cycler = cycler('color', clist) colors = prop_cycler._transpose().get('color', 'k') c = colors[int(c[1]) % len(colors)] try: From ef4aed5ecbf2d8b4be3961a11cebee1ecdb288d0 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 29 May 2016 15:54:03 -0400 Subject: [PATCH 2/4] MNT: use public cyler API - _transpose() -> by_key() - be pedantic about return types --- lib/matplotlib/colors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index a5ab755cb422..525c80088b7e 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -127,7 +127,7 @@ def to_rgba(c, alpha=None): if _is_nth_color(c): from matplotlib import rcParams prop_cycler = rcParams['axes.prop_cycle'] - colors = prop_cycler._transpose().get('color', 'k') + colors = prop_cycler.by_key().get('color', ['k']) c = colors[int(c[1]) % len(colors)] try: rgba = _colors_full_map.cache[c, alpha] From 701bfb0380d2f319c689581d3b777c6a77275ecb Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 29 May 2016 18:06:20 -0400 Subject: [PATCH 3/4] MNT: remove implicit color from cycler axes._base --- lib/matplotlib/axes/_base.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 3bb856b1ad6f..148306e71d95 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -167,10 +167,6 @@ def set_prop_cycle(self, *args, **kwargs): else: prop_cycler = cycler(*args, **kwargs) - # Make sure the cycler always has at least one color - if 'color' not in prop_cycler.keys: - prop_cycler = prop_cycler * cycler('color', ['k']) - self.prop_cycler = itertools.cycle(prop_cycler) # This should make a copy self._prop_keys = prop_cycler.keys @@ -200,6 +196,8 @@ def get_next_color(self): """ Return the next color in the cycle. """ + if 'color' not in self._prop_keys: + return 'k' return six.next(self.prop_cycler)['color'] def set_lineprops(self, line, **kwargs): From dfa14fe95b68440f3304c2a3f0cf9ed1ce9d6114 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 29 May 2016 17:57:45 -0400 Subject: [PATCH 4/4] TST: be explicit about color to make tests pass --- lib/matplotlib/tests/test_cycles.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/tests/test_cycles.py b/lib/matplotlib/tests/test_cycles.py index 06b60caa81ca..4d57b74c68de 100644 --- a/lib/matplotlib/tests/test_cycles.py +++ b/lib/matplotlib/tests/test_cycles.py @@ -69,13 +69,13 @@ def test_linestylecycle_basic(): ax.set_prop_cycle(cycler('ls', ['-', '--', ':'])) xs = np.arange(10) ys = 0.25 * xs + 2 - ax.plot(xs, ys, label='solid', lw=4) + ax.plot(xs, ys, label='solid', lw=4, color='k') ys = 0.45 * xs + 3 - ax.plot(xs, ys, label='dashed', lw=4) + ax.plot(xs, ys, label='dashed', lw=4, color='k') ys = 0.65 * xs + 4 - ax.plot(xs, ys, label='dotted', lw=4) + ax.plot(xs, ys, label='dotted', lw=4, color='k') ys = 0.85 * xs + 5 - ax.plot(xs, ys, label='solid2', lw=4) + ax.plot(xs, ys, label='solid2', lw=4, color='k') ax.legend(loc='upper left') @@ -130,8 +130,8 @@ def test_property_collision_plot(): ax.set_prop_cycle('linewidth', [2, 4]) for c in range(1, 4): ax.plot(np.arange(10), c * np.arange(10), lw=0.1, color='k') - ax.plot(np.arange(10), 4 * np.arange(10)) - ax.plot(np.arange(10), 5 * np.arange(10)) + ax.plot(np.arange(10), 4 * np.arange(10), color='k') + ax.plot(np.arange(10), 5 * np.arange(10), color='k') @image_comparison(baseline_images=['property_collision_fill'],