diff --git a/lib/matplotlib/tests/baseline_images/test_patches/patch_alpha_coloring.pdf b/lib/matplotlib/tests/baseline_images/test_patches/patch_alpha_coloring.pdf new file mode 100644 index 000000000000..9a20b7e98bbf Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_patches/patch_alpha_coloring.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_patches/patch_alpha_coloring.png b/lib/matplotlib/tests/baseline_images/test_patches/patch_alpha_coloring.png new file mode 100644 index 000000000000..42cc139085f7 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_patches/patch_alpha_coloring.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_patches/patch_alpha_coloring.svg b/lib/matplotlib/tests/baseline_images/test_patches/patch_alpha_coloring.svg new file mode 100644 index 000000000000..9c008f857138 --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_patches/patch_alpha_coloring.svg @@ -0,0 +1,311 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index 7fac0a838c39..26c1ce6988af 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -2,7 +2,7 @@ Tests specific to the collections module. """ -import nose.tools +from nose.tools import assert_equal import numpy as np import matplotlib.pyplot as plt from matplotlib.collections import EventCollection @@ -81,7 +81,7 @@ def test__EventCollection__get_orientation(): orientation ''' _, coll, props = generate_EventCollection_plot() - nose.tools.assert_equal(props['orientation'], coll.get_orientation()) + assert_equal(props['orientation'], coll.get_orientation()) @cleanup @@ -91,7 +91,7 @@ def test__EventCollection__is_horizontal(): orientation ''' _, coll, _ = generate_EventCollection_plot() - nose.tools.assert_equal(True, coll.is_horizontal()) + assert_equal(True, coll.is_horizontal()) @cleanup @@ -100,7 +100,7 @@ def test__EventCollection__get_linelength(): check to make sure the default linelength matches the input linelength ''' _, coll, props = generate_EventCollection_plot() - nose.tools.assert_equal(props['linelength'], coll.get_linelength()) + assert_equal(props['linelength'], coll.get_linelength()) @cleanup @@ -109,7 +109,7 @@ def test__EventCollection__get_lineoffset(): check to make sure the default lineoffset matches the input lineoffset ''' _, coll, props = generate_EventCollection_plot() - nose.tools.assert_equal(props['lineoffset'], coll.get_lineoffset()) + assert_equal(props['lineoffset'], coll.get_lineoffset()) @cleanup @@ -118,7 +118,7 @@ def test__EventCollection__get_linestyle(): check to make sure the default linestyle matches the input linestyle ''' _, coll, _ = generate_EventCollection_plot() - nose.tools.assert_equal(coll.get_linestyle(), [(None, None)]) + assert_equal(coll.get_linestyle(), [(None, None)]) @cleanup @@ -213,8 +213,8 @@ def test__EventCollection__switch_orientation(): splt, coll, props = generate_EventCollection_plot() new_orientation = 'vertical' coll.switch_orientation() - nose.tools.assert_equal(new_orientation, coll.get_orientation()) - nose.tools.assert_equal(False, coll.is_horizontal()) + assert_equal(new_orientation, coll.get_orientation()) + assert_equal(False, coll.is_horizontal()) new_positions = coll.get_positions() check_segments(coll, new_positions, @@ -236,8 +236,8 @@ def test__EventCollection__switch_orientation_2x(): coll.switch_orientation() coll.switch_orientation() new_positions = coll.get_positions() - nose.tools.assert_equal(props['orientation'], coll.get_orientation()) - nose.tools.assert_equal(True, coll.is_horizontal()) + assert_equal(props['orientation'], coll.get_orientation()) + assert_equal(True, coll.is_horizontal()) np.testing.assert_array_equal(props['positions'], new_positions) check_segments(coll, new_positions, @@ -255,8 +255,8 @@ def test__EventCollection__set_orientation(): splt, coll, props = generate_EventCollection_plot() new_orientation = 'vertical' coll.set_orientation(new_orientation) - nose.tools.assert_equal(new_orientation, coll.get_orientation()) - nose.tools.assert_equal(False, coll.is_horizontal()) + assert_equal(new_orientation, coll.get_orientation()) + assert_equal(False, coll.is_horizontal()) check_segments(coll, props['positions'], props['linelength'], @@ -275,7 +275,7 @@ def test__EventCollection__set_linelength(): splt, coll, props = generate_EventCollection_plot() new_linelength = 15 coll.set_linelength(new_linelength) - nose.tools.assert_equal(new_linelength, coll.get_linelength()) + assert_equal(new_linelength, coll.get_linelength()) check_segments(coll, props['positions'], new_linelength, @@ -293,7 +293,7 @@ def test__EventCollection__set_lineoffset(): splt, coll, props = generate_EventCollection_plot() new_lineoffset = -5. coll.set_lineoffset(new_lineoffset) - nose.tools.assert_equal(new_lineoffset, coll.get_lineoffset()) + assert_equal(new_lineoffset, coll.get_lineoffset()) check_segments(coll, props['positions'], props['linelength'], @@ -311,7 +311,7 @@ def test__EventCollection__set_linestyle(): splt, coll, _ = generate_EventCollection_plot() new_linestyle = 'dashed' coll.set_linestyle(new_linestyle) - nose.tools.assert_equal(coll.get_linestyle(), [(0, (6.0, 6.0))]) + assert_equal(coll.get_linestyle(), [(0, (6.0, 6.0))]) splt.set_title('EventCollection: set_linestyle') @@ -323,7 +323,7 @@ def test__EventCollection__set_linewidth(): splt, coll, _ = generate_EventCollection_plot() new_linewidth = 5 coll.set_linewidth(new_linewidth) - nose.tools.assert_equal(coll.get_linewidth(), new_linewidth) + assert_equal(coll.get_linewidth(), new_linewidth) splt.set_title('EventCollection: set_linewidth') @@ -362,10 +362,10 @@ def check_segments(coll, positions, linelength, lineoffset, orientation): # test to make sure each segment is correct for i, segment in enumerate(segments): - nose.tools.assert_equal(segment[0, pos1], lineoffset + linelength / 2.) - nose.tools.assert_equal(segment[1, pos1], lineoffset - linelength / 2.) - nose.tools.assert_equal(segment[0, pos2], positions[i]) - nose.tools.assert_equal(segment[1, pos2], positions[i]) + assert_equal(segment[0, pos1], lineoffset + linelength / 2.) + assert_equal(segment[1, pos1], lineoffset - linelength / 2.) + assert_equal(segment[0, pos2], positions[i]) + assert_equal(segment[1, pos2], positions[i]) def check_allprop(values, target): @@ -375,7 +375,7 @@ def check_allprop(values, target): note: this is not a test, it is used by tests ''' for value in values: - nose.tools.assert_equal(value, target) + assert_equal(value, target) def check_allprop_array(values, target): @@ -387,6 +387,7 @@ def check_allprop_array(values, target): for value in values: np.testing.assert_array_equal(value, target) + if __name__ == '_main_': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False) diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index 166b2c820583..ccb8de874e5d 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -9,7 +9,8 @@ from matplotlib.patches import Rectangle from matplotlib.testing.decorators import image_comparison import matplotlib.pyplot as plt -from matplotlib import patches as mpatches +import matplotlib.patches as mpatches +import matplotlib.collections as mcollections from matplotlib import path as mpath from matplotlib import transforms as mtrans @@ -104,3 +105,36 @@ def test_clip_to_bbox(): result_path, alpha=0.5, facecolor='green', lw=4, edgecolor='black') ax.add_patch(result_patch) + + +@image_comparison(baseline_images=['patch_alpha_coloring'], remove_text=True) +def test_patch_alpha_coloring(): + star = mpath.Path.unit_regular_star(6) + circle = mpath.Path.unit_circle() + # concatenate the star with an internal cutout of the circle + verts = np.concatenate([circle.vertices, star.vertices[::-1]]) + codes = np.concatenate([circle.codes, star.codes]) + cut_star1 = mpath.Path(verts, codes) + cut_star2 = mpath.Path(verts + 1, codes) + + ax = plt.axes() + patch = mpatches.PathPatch(cut_star1, + linewidth=5, linestyle='dashdot', + facecolor=(1, 0, 0, 0.5), + edgecolor=(0, 0, 1, 0.75)) + ax.add_patch(patch) + + col = mcollections.PathCollection([cut_star2], + linewidth=5, linestyles='dashdot', + facecolor=(1, 0, 0, 0.5), + edgecolor=(0, 0, 1, 0.75)) + ax.add_collection(col) + + ax.set_xlim([-1, 2]) + ax.set_ylim([-1, 2]) + + + +if __name__=='__main__': + import nose + nose.runmodule(argv=['-s','--with-doctest'], exit=False)