test_backend_cairo.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import numpy as np
  2. import pytest
  3. from matplotlib.testing.decorators import check_figures_equal
  4. from matplotlib import (
  5. collections as mcollections, patches as mpatches, path as mpath)
  6. @pytest.mark.backend('cairo')
  7. @check_figures_equal(extensions=["png"])
  8. def test_patch_alpha_coloring(fig_test, fig_ref):
  9. """
  10. Test checks that the patch and collection are rendered with the specified
  11. alpha values in their facecolor and edgecolor.
  12. """
  13. star = mpath.Path.unit_regular_star(6)
  14. circle = mpath.Path.unit_circle()
  15. # concatenate the star with an internal cutout of the circle
  16. verts = np.concatenate([circle.vertices, star.vertices[::-1]])
  17. codes = np.concatenate([circle.codes, star.codes])
  18. cut_star1 = mpath.Path(verts, codes)
  19. cut_star2 = mpath.Path(verts + 1, codes)
  20. # Reference: two separate patches
  21. ax = fig_ref.subplots()
  22. ax.set_xlim([-1, 2])
  23. ax.set_ylim([-1, 2])
  24. patch = mpatches.PathPatch(cut_star1,
  25. linewidth=5, linestyle='dashdot',
  26. facecolor=(1, 0, 0, 0.5),
  27. edgecolor=(0, 0, 1, 0.75))
  28. ax.add_patch(patch)
  29. patch = mpatches.PathPatch(cut_star2,
  30. linewidth=5, linestyle='dashdot',
  31. facecolor=(1, 0, 0, 0.5),
  32. edgecolor=(0, 0, 1, 0.75))
  33. ax.add_patch(patch)
  34. # Test: path collection
  35. ax = fig_test.subplots()
  36. ax.set_xlim([-1, 2])
  37. ax.set_ylim([-1, 2])
  38. col = mcollections.PathCollection([cut_star1, cut_star2],
  39. linewidth=5, linestyles='dashdot',
  40. facecolor=(1, 0, 0, 0.5),
  41. edgecolor=(0, 0, 1, 0.75))
  42. ax.add_collection(col)