Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 1 addition & 5 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/tests/test_cycles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')


Expand Down Expand Up @@ -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'],
Expand Down