test__plotutils.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import pytest
  2. from numpy.testing import assert_, assert_array_equal, suppress_warnings
  3. try:
  4. import matplotlib
  5. matplotlib.rcParams['backend'] = 'Agg'
  6. import matplotlib.pyplot as plt
  7. has_matplotlib = True
  8. except Exception:
  9. has_matplotlib = False
  10. from scipy.spatial import \
  11. delaunay_plot_2d, voronoi_plot_2d, convex_hull_plot_2d, \
  12. Delaunay, Voronoi, ConvexHull
  13. @pytest.mark.skipif(not has_matplotlib, reason="Matplotlib not available")
  14. class TestPlotting:
  15. points = [(0,0), (0,1), (1,0), (1,1)]
  16. def test_delaunay(self):
  17. # Smoke test
  18. fig = plt.figure()
  19. obj = Delaunay(self.points)
  20. s_before = obj.simplices.copy()
  21. with suppress_warnings() as sup:
  22. # filter can be removed when matplotlib 1.x is dropped
  23. sup.filter(message="The ishold function was deprecated in version")
  24. r = delaunay_plot_2d(obj, ax=fig.gca())
  25. assert_array_equal(obj.simplices, s_before) # shouldn't modify
  26. assert_(r is fig)
  27. delaunay_plot_2d(obj, ax=fig.gca())
  28. def test_voronoi(self):
  29. # Smoke test
  30. fig = plt.figure()
  31. obj = Voronoi(self.points)
  32. with suppress_warnings() as sup:
  33. # filter can be removed when matplotlib 1.x is dropped
  34. sup.filter(message="The ishold function was deprecated in version")
  35. r = voronoi_plot_2d(obj, ax=fig.gca())
  36. assert_(r is fig)
  37. voronoi_plot_2d(obj)
  38. voronoi_plot_2d(obj, show_vertices=False)
  39. def test_convex_hull(self):
  40. # Smoke test
  41. fig = plt.figure()
  42. tri = ConvexHull(self.points)
  43. with suppress_warnings() as sup:
  44. # filter can be removed when matplotlib 1.x is dropped
  45. sup.filter(message="The ishold function was deprecated in version")
  46. r = convex_hull_plot_2d(tri, ax=fig.gca())
  47. assert_(r is fig)
  48. convex_hull_plot_2d(tri)