Skip to content

Commit fd5d646

Browse files
committed
feat: add missing contour builder test
1 parent 4caab38 commit fd5d646

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Licensed under the terms of the BSD 3-Clause
4+
# (see plotpy/LICENSE for details)
5+
6+
"""Contour builder test"""
7+
8+
# guitest: show
9+
10+
import numpy as np
11+
from guidata.qthelpers import qt_app_context
12+
13+
from plotpy.builder import make
14+
from plotpy.items import ContourItem
15+
from plotpy.tests import vistools as ptv
16+
17+
18+
def create_two_gaussians() -> np.ndarray:
19+
"""Create two nearby 2D Gaussians with different shapes."""
20+
axis = np.linspace(-5.0, 5.0, 300)
21+
x, y = np.meshgrid(axis, axis)
22+
wide = np.exp(-((x + 0.9) ** 2 + (y + 0.2) ** 2) / (2.0 * 1.2**2))
23+
narrow = 0.65 * np.exp(-((x - 1.0) ** 2 + (y - 0.4) ** 2) / (2.0 * 0.6**2))
24+
return wide + narrow
25+
26+
27+
def test_contours():
28+
"""Contour plotting on two nearby 2D Gaussians"""
29+
with qt_app_context(exec_loop=True):
30+
image = create_two_gaussians()
31+
contour_items = make.contours(image, np.linspace(0.2, 1.0, 5))
32+
33+
assert contour_items
34+
assert all(isinstance(item, ContourItem) for item in contour_items)
35+
36+
_win = ptv.show_items(
37+
[make.image(image, colormap="cool")] + contour_items,
38+
wintitle=test_contours.__doc__,
39+
curve_antialiasing=False,
40+
lock_aspect_ratio=True,
41+
)
42+
43+
44+
if __name__ == "__main__":
45+
test_contours()

0 commit comments

Comments
 (0)