test_backend_cairo.py 1.9 KB

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