Skip to content

Commit 51aa8cf

Browse files
committed
Remove usage of nodes from more examples
1 parent 958eb83 commit 51aa8cf

File tree

5 files changed

+82
-34
lines changed

5 files changed

+82
-34
lines changed

Diff for: data_prototype/image.py

+8
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ def __init__(self, container, edges=None, norm=None, cmap=None, **kwargs):
7676
{"image": Desc(("O", "P", 4), "rgba_resampled")},
7777
{"image": Desc(("O", "P", 4), "display")},
7878
),
79+
FuncEdge.from_func(
80+
"rgb_rgba",
81+
lambda image: np.append(
82+
image, np.ones(image.shape[:-1] + (1,)), axis=-1
83+
),
84+
{"image": Desc(("M", "N", 3), "rgb")},
85+
{"image": Desc(("M", "N", 4), "rgba")},
86+
),
7987
self._interpolation_edge,
8088
]
8189

Diff for: data_prototype/line.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, container, edges=None, **kwargs):
1818

1919
scalar = Desc((), "display") # ... this needs thinking...
2020

21-
edges = [
21+
default_edges = [
2222
CoordinateEdge.from_coords("xycoords", {"x": "auto", "y": "auto"}, "data"),
2323
CoordinateEdge.from_coords("color", {"color": Desc(())}, "display"),
2424
CoordinateEdge.from_coords("linewidth", {"linewidth": Desc(())}, "display"),
@@ -45,7 +45,7 @@ def __init__(self, container, edges=None, **kwargs):
4545
DefaultEdge.from_default_value("mew_def", "markeredgewidth", scalar, 1),
4646
DefaultEdge.from_default_value("marker_def", "marker", scalar, "None"),
4747
]
48-
self._graph = self._graph + Graph(edges)
48+
self._graph = self._graph + Graph(default_edges)
4949
# Currently ignoring:
5050
# - cap/join style
5151
# - url

Diff for: examples/2Dfunc.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import matplotlib.pyplot as plt
1111
import numpy as np
1212

13-
from data_prototype.wrappers import ImageWrapper
13+
from data_prototype.artist import CompatibilityAxes
14+
from data_prototype.image import Image
1415
from data_prototype.containers import FuncContainer
1516

1617
from matplotlib.colors import Normalize
@@ -19,20 +20,23 @@
1920
fc = FuncContainer(
2021
{},
2122
xyfuncs={
22-
"xextent": ((2,), lambda x, y: [x[0], x[-1]]),
23-
"yextent": ((2,), lambda x, y: [y[0], y[-1]]),
23+
"x": ((2,), lambda x, y: [x[0], x[-1]]),
24+
"y": ((2,), lambda x, y: [y[0], y[-1]]),
2425
"image": (
2526
("N", "M"),
2627
lambda x, y: np.sin(x).reshape(1, -1) * np.cos(y).reshape(-1, 1),
2728
),
2829
},
2930
)
3031
norm = Normalize(vmin=-1, vmax=1)
31-
im = ImageWrapper(fc, norm=norm)
32+
im = Image(fc, norm=norm)
33+
34+
fig, nax = plt.subplots()
35+
ax = CompatibilityAxes(nax)
36+
nax.add_artist(ax)
3237

33-
fig, ax = plt.subplots()
3438
ax.add_artist(im)
3539
ax.set_xlim(-5, 5)
3640
ax.set_ylim(-5, 5)
37-
fig.colorbar(im)
41+
# fig.colorbar(im, ax=nax)
3842
plt.show()

Diff for: examples/mapped.py

+45-20
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
import numpy as np
1212

1313
from matplotlib.colors import Normalize
14+
from matplotlib.font_manager import FontProperties
1415

15-
from data_prototype.wrappers import FormattedText
16-
from data_prototype.artist import CompatibilityArtist as CA
16+
from data_prototype.artist import CompatibilityAxes
1717
from data_prototype.line import Line
1818
from data_prototype.containers import ArrayContainer
1919
from data_prototype.description import Desc
20-
from data_prototype.conversion_node import FunctionConversionNode
2120
from data_prototype.conversion_edge import FuncEdge
21+
from data_prototype.text import Text
2222

2323

2424
cmap = plt.colormaps["viridis"]
@@ -49,19 +49,41 @@
4949
),
5050
]
5151

52-
text_converter = FunctionConversionNode.from_funcs(
53-
{
54-
"text": lambda j, cat: f"index={j[()]} class={cat!r}",
55-
"y": lambda j: j,
56-
"x": lambda x: 2 * np.pi,
57-
},
58-
)
52+
text_edges = [
53+
FuncEdge.from_func(
54+
"text",
55+
lambda j, cat: f"index={j[()]} class={cat!r}",
56+
{"j": Desc((), "auto"), "cat": Desc((), "auto")},
57+
{"text": Desc((), "display")},
58+
),
59+
FuncEdge.from_func(
60+
"y",
61+
lambda j: j,
62+
{"j": Desc((), "auto")},
63+
{"y": Desc((), "data")},
64+
),
65+
FuncEdge.from_func(
66+
"x",
67+
lambda: 2 * np.pi,
68+
{},
69+
{"x": Desc((), "data")},
70+
),
71+
FuncEdge.from_func(
72+
"color",
73+
lambda: (0, 0, 0, 1),
74+
{},
75+
{"color": Desc((4,), "rgba")},
76+
),
77+
]
5978

6079

6180
th = np.linspace(0, 2 * np.pi, 128)
6281
delta = np.pi / 9
6382

64-
fig, ax = plt.subplots()
83+
fig, nax = plt.subplots()
84+
85+
ax = CompatibilityAxes(nax)
86+
nax.add_artist(ax)
6587

6688
for j in range(10):
6789
ac = ArrayContainer(
@@ -74,20 +96,23 @@
7496
}
7597
)
7698
ax.add_artist(
77-
CA(
78-
Line(
79-
ac,
80-
line_edges,
81-
)
99+
Line(
100+
ac,
101+
line_edges,
82102
)
83103
)
84104
ax.add_artist(
85-
FormattedText(
105+
Text(
86106
ac,
87-
text_converter,
107+
text_edges,
88108
x=2 * np.pi,
89-
ha="right",
90-
bbox={"facecolor": "gray", "alpha": 0.5},
109+
# ha="right",
110+
# bbox={"facecolor": "gray", "alpha": 0.5},
111+
antialiased=False,
112+
fontproperties=FontProperties(),
113+
rotation=0,
114+
alpha=1,
115+
usetex=False,
91116
)
92117
)
93118
ax.set_xlim(0, np.pi * 2)

Diff for: examples/mulivariate_cmap.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
import matplotlib.pyplot as plt
1212
import numpy as np
1313

14-
from data_prototype.wrappers import ImageWrapper
14+
from data_prototype.image import Image
15+
from data_prototype.artist import CompatibilityAxes
16+
from data_prototype.description import Desc
1517
from data_prototype.containers import FuncContainer
16-
from data_prototype.conversion_node import FunctionConversionNode
18+
from data_prototype.conversion_edge import FuncEdge
1719

1820
from matplotlib.colors import hsv_to_rgb
1921

@@ -35,15 +37,24 @@ def image_nu(image):
3537
fc = FuncContainer(
3638
{},
3739
xyfuncs={
38-
"xextent": ((2,), lambda x, y: [x[0], x[-1]]),
39-
"yextent": ((2,), lambda x, y: [y[0], y[-1]]),
40+
"x": ((2,), lambda x, y: [x[0], x[-1]]),
41+
"y": ((2,), lambda x, y: [y[0], y[-1]]),
4042
"image": (("N", "M", 2), func),
4143
},
4244
)
4345

44-
im = ImageWrapper(fc, FunctionConversionNode.from_funcs({"image": image_nu}))
46+
image_edges = FuncEdge.from_func(
47+
"image",
48+
image_nu,
49+
{"image": Desc(("M", "N", 2), "auto")},
50+
{"image": Desc(("M", "N", 3), "rgb")},
51+
)
52+
53+
im = Image(fc, [image_edges])
4554

46-
fig, ax = plt.subplots()
55+
fig, nax = plt.subplots()
56+
ax = CompatibilityAxes(nax)
57+
nax.add_artist(ax)
4758
ax.add_artist(im)
4859
ax.set_xlim(-5, 5)
4960
ax.set_ylim(-5, 5)

0 commit comments

Comments
 (0)