-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_figure.py
More file actions
58 lines (44 loc) · 1.76 KB
/
test_figure.py
File metadata and controls
58 lines (44 loc) · 1.76 KB
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
48
49
50
51
52
53
54
55
56
57
"""Smoke test — run with: python3 test_figure.py"""
import numpy as np
import anyplotlib as vw
import json
# --- subplots 2x1 ---
fig, axs = vw.subplots(2, 1, figsize=(400, 300))
assert axs.shape == (2,), f"Expected shape (2,), got {axs.shape}"
v2d = axs[0].imshow(np.random.rand(64, 64))
v1d = axs[1].plot(np.sin(np.linspace(0, 6, 128)))
# layout_json sanity
L = json.loads(fig.layout_json)
assert L["nrows"] == 2, f"nrows={L['nrows']}"
assert len(L["panel_specs"]) == 2, f"panel_specs={L['panel_specs']}"
# panel trait exists
assert fig.has_trait(f"panel_{v2d._id}_json"), "missing panel trait for v2d"
assert fig.has_trait(f"panel_{v1d._id}_json"), "missing panel trait for v1d"
# marker add
mg = v2d.add_circles(np.array([[16., 16.], [32., 32.]]),
name="g1", facecolors="red", radius=5)
assert v2d.markers["circles"]["g1"]._data["radius"] == 5
# marker live update
v2d.markers["circles"]["g1"].set(radius=8)
assert v2d.markers["circles"]["g1"]._data["radius"] == 8
# auto-name
mg2 = v2d.add_circles(np.array([[48., 48.]]), radius=3)
assert "circles_1" in v2d.markers["circles"], \
f"auto-name failed: {list(v2d.markers['circles'].keys())}"
# 1D markers
v1d.add_vlines([1.0, 2.0, 3.0], name="peaks")
assert "peaks" in v1d.markers["vlines"]
# GridSpec
gs = vw.GridSpec(2, 3, width_ratios=[2, 1, 1])
s = gs[0, :]
assert s.col_start == 0 and s.col_stop == 3
s2 = gs[1, 1]
assert s2.row_start == 1 and s2.col_start == 1
# subplots squeeze shapes
fig1, ax1 = vw.subplots(1, 1)
assert not hasattr(ax1, 'shape'), "1x1 should return scalar Axes"
fig2, axs2 = vw.subplots(1, 3)
assert axs2.shape == (3,), f"1x3 should be 1-D, got {axs2.shape}"
fig3, axs3 = vw.subplots(2, 2)
assert axs3.shape == (2, 2), f"2x2 should be 2-D, got {axs3.shape}"
print("ALL TESTS PASSED")