Skip to content

Commit

Permalink
Merge pull request matplotlib#5536 from WeatherGod/fix_cycle_reset
Browse files Browse the repository at this point in the history
Fix the resetting of color cycles
  • Loading branch information
tacaswell committed Nov 24, 2015
2 parents 8fcbf60 + eed693f commit 6258dad
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,13 @@ def set_color_cycle(self, clist):
"""
cbook.warn_deprecated(
'1.5', name='set_color_cycle', alternative='set_prop_cycle')
self.set_prop_cycle('color', clist)
if clist is None:
# Calling set_color_cycle() or set_prop_cycle() with None
# effectively resets the cycle, but you can't do
# set_prop_cycle('color', None). So we are special-casing this.
self.set_prop_cycle(None)
else:
self.set_prop_cycle('color', clist)

def ishold(self):
"""return the HOLD status of the axes"""
Expand Down
26 changes: 26 additions & 0 deletions lib/matplotlib/tests/test_cycles.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

from matplotlib.testing.decorators import image_comparison, cleanup
import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -147,6 +149,30 @@ def test_valid_input_forms():
assert True


@cleanup
def test_cycle_reset():
fig, ax = plt.subplots()

# Can't really test a reset because only a cycle object is stored
# but we can test the first item of the cycle.
prop = next(ax._get_lines.prop_cycler)
ax.set_prop_cycle(linewidth=[10, 9, 4])
assert prop != next(ax._get_lines.prop_cycler)
ax.set_prop_cycle(None)
got = next(ax._get_lines.prop_cycler)
assert prop == got, "expected %s, got %s" % (prop, got)

fig, ax = plt.subplots()
# Need to double-check the old set/get_color_cycle(), too
with warnings.catch_warnings():
prop = next(ax._get_lines.prop_cycler)
ax.set_color_cycle(['c', 'm', 'y', 'k'])
assert prop != next(ax._get_lines.prop_cycler)
ax.set_color_cycle(None)
got = next(ax._get_lines.prop_cycler)
assert prop == got, "expected %s, got %s" % (prop, got)


@cleanup
def test_invalid_input_forms():
fig, ax = plt.subplots()
Expand Down

0 comments on commit 6258dad

Please sign in to comment.