diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 15c45b122f5f..148306e71d95 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -164,16 +164,9 @@ 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) - # 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 @@ -203,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): diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 8a2efaea3f50..525c80088b7e 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -126,12 +126,8 @@ 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') + colors = prop_cycler.by_key().get('color', ['k']) c = colors[int(c[1]) % len(colors)] try: rgba = _colors_full_map.cache[c, alpha] 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'],