|
1 |
| -from matplotlib.testing.decorators import image_comparison |
| 1 | +from matplotlib.testing.decorators import image_comparison, cleanup |
2 | 2 | import matplotlib.pyplot as plt
|
3 | 3 | import numpy as np
|
| 4 | +from nose.tools import assert_raises |
4 | 5 |
|
5 | 6 | from cycler import cycler
|
6 | 7 |
|
@@ -42,6 +43,27 @@ def test_marker_cycle():
|
42 | 43 | ax.legend(loc='upper left')
|
43 | 44 |
|
44 | 45 |
|
| 46 | +# Reuse the image from test_marker_cycle() |
| 47 | +@image_comparison(baseline_images=['marker_cycle'], remove_text=True, |
| 48 | + extensions=['png']) |
| 49 | +def test_marker_cycle_keywords(): |
| 50 | + fig = plt.figure() |
| 51 | + ax = fig.add_subplot(111) |
| 52 | + # Test keyword arguments, numpy arrays, and generic iterators |
| 53 | + ax.set_prop_cycle(color=np.array(['r', 'g', 'y']), |
| 54 | + marker=iter(['.', '*', 'x'])) |
| 55 | + xs = np.arange(10) |
| 56 | + ys = 0.25 * xs + 2 |
| 57 | + ax.plot(xs, ys, label='red dot', lw=4, ms=16) |
| 58 | + ys = 0.45 * xs + 3 |
| 59 | + ax.plot(xs, ys, label='green star', lw=4, ms=16) |
| 60 | + ys = 0.65 * xs + 4 |
| 61 | + ax.plot(xs, ys, label='yellow x', lw=4, ms=16) |
| 62 | + ys = 0.85 * xs + 5 |
| 63 | + ax.plot(xs, ys, label='red2 dot', lw=4, ms=16) |
| 64 | + ax.legend(loc='upper left') |
| 65 | + |
| 66 | + |
45 | 67 | @image_comparison(baseline_images=['lineprop_cycle_basic'], remove_text=True,
|
46 | 68 | extensions=['png'])
|
47 | 69 | def test_linestylecycle_basic():
|
@@ -104,6 +126,44 @@ def test_fillcycle_ignore():
|
104 | 126 | ax.legend(loc='upper left')
|
105 | 127 |
|
106 | 128 |
|
| 129 | +@cleanup |
| 130 | +def test_valid_input_forms(): |
| 131 | + fig, ax = plt.subplots() |
| 132 | + # These should not raise an error. |
| 133 | + ax.set_prop_cycle(None) |
| 134 | + ax.set_prop_cycle(cycler('linewidth', [1, 2])) |
| 135 | + ax.set_prop_cycle('color', 'rgywkbcm') |
| 136 | + ax.set_prop_cycle('linewidth', (1, 2)) |
| 137 | + ax.set_prop_cycle('linewidth', [1, 2]) |
| 138 | + ax.set_prop_cycle('linewidth', iter([1, 2])) |
| 139 | + ax.set_prop_cycle('linewidth', np.array([1, 2])) |
| 140 | + ax.set_prop_cycle('color', np.array([[1, 0, 0], |
| 141 | + [0, 1, 0], |
| 142 | + [0, 0, 1]])) |
| 143 | + ax.set_prop_cycle(lw=[1, 2], color=['k', 'w'], ls=['-', '--']) |
| 144 | + ax.set_prop_cycle(lw=np.array([1, 2]), |
| 145 | + color=np.array(['k', 'w']), |
| 146 | + ls=np.array(['-', '--'])) |
| 147 | + assert True |
| 148 | + |
| 149 | + |
| 150 | +@cleanup |
| 151 | +def test_invalid_input_forms(): |
| 152 | + fig, ax = plt.subplots() |
| 153 | + with assert_raises((TypeError, ValueError)): |
| 154 | + ax.set_prop_cycle(1) |
| 155 | + with assert_raises((TypeError, ValueError)): |
| 156 | + ax.set_prop_cycle([1, 2]) |
| 157 | + with assert_raises((TypeError, ValueError)): |
| 158 | + ax.set_prop_cycle('color', 'fish') |
| 159 | + with assert_raises((TypeError, ValueError)): |
| 160 | + ax.set_prop_cycle('linewidth', 1) |
| 161 | + with assert_raises((TypeError, ValueError)): |
| 162 | + ax.set_prop_cycle('linewidth', {'1': 1, '2': 2}) |
| 163 | + with assert_raises((TypeError, ValueError)): |
| 164 | + ax.set_prop_cycle(linewidth=1, color='r') |
| 165 | + |
| 166 | + |
107 | 167 | if __name__ == '__main__':
|
108 | 168 | import nose
|
109 | 169 | nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
|
0 commit comments