-
Notifications
You must be signed in to change notification settings - Fork 19
/
test_generic.py
47 lines (39 loc) · 1.33 KB
/
test_generic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from os.path import dirname, realpath
import matplotlib.cbook as cbook
import matplotlib.pyplot as plt
import numpy as np
import pytest
from matplotlib import __version__ as mpl_version
from packaging import version
from mpl_interactions.generic import *
if version.parse(mpl_version) >= version.parse("3.3"):
mplsuffix = ""
else:
mplsuffix = 32
@pytest.mark.mpl_image_compare(style="default", filename=f"test_heatmap_slicer{mplsuffix}.png")
def test_heatmap_slicer():
x = np.linspace(0, np.pi, 100)
y = np.linspace(0, 10, 200)
X, Y = np.meshgrid(x, y)
data1 = np.sin(X) + np.exp(np.cos(Y))
data2 = np.cos(X) + np.exp(np.sin(Y))
fig, axes = heatmap_slicer(
x,
y,
(data1, data2),
slices="both",
heatmap_names=("dataset 1", "dataset 2"),
labels=("Some wild X variable", "Y axis"),
interaction_type="move",
cmap="plasma",
)
return fig
@pytest.mark.mpl_image_compare(style="default")
def test_image_segmentation():
image = plt.imread(
"https://github.com/matplotlib/matplotlib/raw/v3.3.0/lib/matplotlib/mpl-data/sample_data/ada.png"
)
script_dir = realpath(dirname(__file__))
mask = np.load(f"{script_dir}/../docs/examples/ada-mask.npy")
preloaded = image_segmenter(image, nclasses=3, mask=mask)
return preloaded.fig