Skip to content

Commit 0eac35e

Browse files
committed
ENH: show off using multiple inputs + renaming
1 parent cc7a67f commit 0eac35e

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

data_prototype/wrappers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ def draw(self, renderer):
280280

281281
def _update_wrapped(self, data):
282282
for k, v in data.items():
283-
k = {"x": "xdata", "y": "ydata"}.get(k, k)
284283
getattr(self._wrapped_instance, f"set_{k}")(v)
285284

286285

examples/mapped.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from matplotlib.colors import Normalize
1515

16-
from data_prototype.wrappers import LineWrapper
16+
from data_prototype.wrappers import LineWrapper, FormatedText
1717
from data_prototype.containers import ArrayContainer
1818

1919
cmap = plt.colormaps["viridis"]
@@ -25,9 +25,9 @@
2525
# arbitrary functions
2626
"lw": lambda lw: min(1 + lw, 5),
2727
# standard color mapping
28-
"color": lambda color: cmap(norm(color)),
28+
"color": lambda j: cmap(norm(j)),
2929
# categorical
30-
"ls": lambda ls: {"A": "-", "B": ":", "C": "--"}[ls[()]],
30+
"ls": lambda cat: {"A": "-", "B": ":", "C": "--"}[cat[()]],
3131
}
3232

3333
th = np.linspace(0, 2 * np.pi, 128)
@@ -36,21 +36,30 @@
3636
fig, ax = plt.subplots()
3737

3838
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+
)
3948
ax.add_artist(
4049
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,
5051
nus,
5152
)
5253
)
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+
)
5463
ax.set_xlim(0, np.pi * 2)
5564
ax.set_ylim(-1.1, 10.1)
5665

0 commit comments

Comments
 (0)