|
| 1 | +from matplotlib.testing.decorators import image_comparison |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +import numpy as np |
| 4 | + |
| 5 | +from cycler import cycler |
| 6 | + |
| 7 | +@image_comparison(baseline_images=['color_cycle_basic'], remove_text=True, |
| 8 | + extensions=['png']) |
| 9 | +def test_colorcycle_basic(): |
| 10 | + fig = plt.figure() |
| 11 | + ax = fig.add_subplot(111) |
| 12 | + ax.set_prop_cycle(cycler('color', ['r', 'g', 'y'])) |
| 13 | + xs = np.arange(10) |
| 14 | + ys = 0.25 * xs + 2 |
| 15 | + ax.plot(xs, ys, label='red', lw=4) |
| 16 | + ys = 0.45 * xs + 3 |
| 17 | + ax.plot(xs, ys, label='green', lw=4) |
| 18 | + ys = 0.65 * xs + 4 |
| 19 | + ax.plot(xs, ys, label='yellow', lw=4) |
| 20 | + ys = 0.85 * xs + 5 |
| 21 | + ax.plot(xs, ys, label='red2', lw=4) |
| 22 | + ax.legend(loc='upper left') |
| 23 | + |
| 24 | + |
| 25 | +@image_comparison(baseline_images=['lineprop_cycle_basic'], remove_text=True, |
| 26 | + extensions=['png']) |
| 27 | +def test_linestylecycle_basic(): |
| 28 | + fig = plt.figure() |
| 29 | + ax = fig.add_subplot(111) |
| 30 | + ax.set_prop_cycle(cycler('linestyle', ['-', '--', ':'])) |
| 31 | + xs = np.arange(10) |
| 32 | + ys = 0.25 * xs + 2 |
| 33 | + ax.plot(xs, ys, label='solid', lw=4) |
| 34 | + ys = 0.45 * xs + 3 |
| 35 | + ax.plot(xs, ys, label='dashed', lw=4) |
| 36 | + ys = 0.65 * xs + 4 |
| 37 | + ax.plot(xs, ys, label='dotted', lw=4) |
| 38 | + ys = 0.85 * xs + 5 |
| 39 | + ax.plot(xs, ys, label='solid2', lw=4) |
| 40 | + ax.legend(loc='upper left') |
| 41 | + |
| 42 | +@image_comparison(baseline_images=['fill_cycle_basic'], remove_text=True, |
| 43 | + extensions=['png']) |
| 44 | +def test_fillcycle_basic(): |
| 45 | + fig = plt.figure() |
| 46 | + ax = fig.add_subplot(111) |
| 47 | + ax.set_prop_cycle(cycler('color', ['red', 'green', 'yellow']))# + |
| 48 | + #cycler('hatch', ['xx', 'O', '|-'])) |
| 49 | + xs = np.arange(10) |
| 50 | + ys = 0.25 * xs**.5 + 2 |
| 51 | + ax.fill(xs, ys, label='red, x') |
| 52 | + ys = 0.45 * xs**.5 + 3 |
| 53 | + ax.fill(xs, ys, label='green, circle') |
| 54 | + ys = 0.65 * xs**.5 + 4 |
| 55 | + ax.fill(xs, ys, label='yellow, cross') |
| 56 | + ys = 0.85 * xs**.5 + 5 |
| 57 | + ax.fill(xs, ys, label='red2, x2') |
| 58 | + ax.legend(loc='upper left') |
| 59 | + |
| 60 | + |
| 61 | +if __name__ == '__main__': |
| 62 | + import nose |
| 63 | + nose.runmodule(argv=['-s', '--with-doctest'], exit=False) |
| 64 | + |
0 commit comments