Skip to content

Commit

Permalink
Test coverage bump - pyrolite.util.plot.interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
morganjwilliams committed Feb 20, 2024
1 parent fc82af5 commit f69f8d5
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion test/util/plot/util_plot_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,33 @@

import matplotlib.patches
import matplotlib.path
import matplotlib.pyplot as plt
import numpy as np

from pyrolite.util.plot.interpolation import interpolated_patch_path
from pyrolite.util.plot.interpolation import (
get_contour_paths,
interpolate_path,
interpolated_patch_path,
)


class TestInterpolatePath(unittest.TestCase):

def setUp(self):
self.fig, self.ax = plt.subplots(1)
self.ax.plot([0, 1, 2, 3, 0], [0, 0.1, 1, 2, 0]) # a closed path
self.path = self.ax.lines[0].get_path()

def test_interpolate(self):
for aspath in (True, False):
for closefirst in (True, False):
with self.subTest(aspath=aspath, closefirst=closefirst):
interp_path = interpolate_path(
self.path, aspath=aspath, closefirst=closefirst
)

def tearDown(self):
plt.close("all")


class InterpolatedPathPatch(unittest.TestCase):
Expand All @@ -25,5 +50,31 @@ def test_resolution(self):
self.assertTrue(path.vertices.shape[0] == res)


class TestContourPaths(unittest.TestCase):

def setUp(self):
self.fig, self.ax = plt.subplots(1)
# this is the contour demo data from matplotlib, for refrence
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-(X**2) - Y**2)
Z2 = np.exp(-((X - 1) ** 2) - (Y - 1) ** 2)
Z = (Z1 - Z2) * 2
self.contours = self.ax.contour(X, Y, Z, inline=False)

def test_default(self):
paths, names, styles = get_contour_paths(self.ax)
self.assertTrue(len(set([len(paths), len(names), len(styles)])) == 1)
self.ax.clabel(self.contours, inline=True)
paths, names, styles = get_contour_paths(self.ax)
self.assertTrue(len(set([len(paths), len(names), len(styles)])) == 1)
self.assertTrue(names[0] is not None)

def tearDown(self):
plt.close("all")


if __name__ == "__main__":
unittest.main()

0 comments on commit f69f8d5

Please sign in to comment.