|
13 | 13 |
|
14 | 14 | from matplotlib.colors import Normalize
|
15 | 15 |
|
16 |
| -from data_prototype.wrappers import LineWrapper |
| 16 | +from data_prototype.wrappers import LineWrapper, FormatedText |
17 | 17 | from data_prototype.containers import ArrayContainer
|
18 | 18 |
|
19 | 19 | cmap = plt.colormaps["viridis"]
|
|
25 | 25 | # arbitrary functions
|
26 | 26 | "lw": lambda lw: min(1 + lw, 5),
|
27 | 27 | # standard color mapping
|
28 |
| - "color": lambda color: cmap(norm(color)), |
| 28 | + "color": lambda j: cmap(norm(j)), |
29 | 29 | # categorical
|
30 |
| - "ls": lambda ls: {"A": "-", "B": ":", "C": "--"}[ls[()]], |
| 30 | + "ls": lambda cat: {"A": "-", "B": ":", "C": "--"}[cat[()]], |
31 | 31 | }
|
32 | 32 |
|
33 | 33 | th = np.linspace(0, 2 * np.pi, 128)
|
|
36 | 36 | fig, ax = plt.subplots()
|
37 | 37 |
|
38 | 38 | for j in range(10):
|
| 39 | + ac = ArrayContainer( |
| 40 | + **{ |
| 41 | + "x": th, |
| 42 | + "y": np.sin(th + j * delta) + j, |
| 43 | + "j": np.asarray(j), |
| 44 | + "lw": np.asarray(j), |
| 45 | + "cat": np.asarray({0: "A", 1: "B", 2: "C"}[j % 3]), |
| 46 | + } |
| 47 | + ) |
39 | 48 | ax.add_artist(
|
40 | 49 | LineWrapper(
|
41 |
| - ArrayContainer( |
42 |
| - **{ |
43 |
| - "x": th, |
44 |
| - "y": np.sin(th + j * delta) + j, |
45 |
| - "color": np.asarray(j), |
46 |
| - "lw": np.asarray(j), |
47 |
| - "ls": np.asarray({0: "A", 1: "B", 2: "C"}[j % 3]), |
48 |
| - } |
49 |
| - ), |
| 50 | + ac, |
50 | 51 | nus,
|
51 | 52 | )
|
52 | 53 | )
|
53 |
| - |
| 54 | + ax.add_artist( |
| 55 | + FormatedText( |
| 56 | + ac, |
| 57 | + {"text": lambda j, cat: f"index={j[()]} class={cat[()]!r}", "y": lambda j: j}, |
| 58 | + x=2 * np.pi, |
| 59 | + ha="right", |
| 60 | + bbox={"facecolor": "gray", "alpha": 0.5}, |
| 61 | + ) |
| 62 | + ) |
54 | 63 | ax.set_xlim(0, np.pi * 2)
|
55 | 64 | ax.set_ylim(-1.1, 10.1)
|
56 | 65 |
|
|
0 commit comments