Skip to content

Commit b66f4ac

Browse files
committed
MNT: make all of the properties on LineWrapper mappable
1 parent de25dd1 commit b66f4ac

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

data_prototype/wrappers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ def draw(self, renderer):
187187
return self._wrapped_instance.draw(renderer)
188188

189189
def _update_wrapped(self, data):
190-
self._wrapped_instance.set_data(data["x"], data["y"])
190+
for k, v in data.items():
191+
getattr(self._wrapped_instance, f"set_{k}")(v)
191192

192193

193194
class ImageWrapper(ProxyWrapper):

examples/mapped.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
=======================
3+
Mapping Line Properties
4+
=======================
5+
6+
Leveraging the nu functions to transform users space data to visualization data.
7+
8+
"""
9+
10+
import matplotlib.pyplot as plt
11+
import numpy as np
12+
import pandas as pd
13+
14+
from matplotlib.colors import Normalize
15+
16+
from data_prototype.wrappers import LineWrapper
17+
from data_prototype.containers import ArrayContainer
18+
19+
cmap = plt.colormaps["viridis"]
20+
cmap.set_over("k")
21+
cmap.set_under("r")
22+
norm = Normalize(1, 8)
23+
24+
nus = {
25+
# arbitrary functions
26+
"lw": lambda lw: min(1 + lw, 5),
27+
# standard color mapping
28+
"color": lambda color: cmap(norm(color)),
29+
# categorical
30+
"ls": lambda ls: {"A": "-", "B": ":", "C": "--"}[ls[()]],
31+
}
32+
33+
th = np.linspace(0, 2 * np.pi, 128)
34+
delta = np.pi / 9
35+
36+
fig, ax = plt.subplots()
37+
38+
for j in range(10):
39+
ax.add_artist(
40+
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+
nus,
51+
)
52+
)
53+
54+
ax.set_xlim(0, np.pi * 2)
55+
ax.set_ylim(-1.1, 10.1)
56+
57+
plt.show()

0 commit comments

Comments
 (0)