test__plotutils.py 2.1 KB

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