diff --git a/data_prototype/image.py b/data_prototype/image.py index 005c76f..786f1e8 100644 --- a/data_prototype/image.py +++ b/data_prototype/image.py @@ -76,6 +76,14 @@ def __init__(self, container, edges=None, norm=None, cmap=None, **kwargs): {"image": Desc(("O", "P", 4), "rgba_resampled")}, {"image": Desc(("O", "P", 4), "display")}, ), + FuncEdge.from_func( + "rgb_rgba", + lambda image: np.append( + image, np.ones(image.shape[:-1] + (1,)), axis=-1 + ), + {"image": Desc(("M", "N", 3), "rgb")}, + {"image": Desc(("M", "N", 4), "rgba")}, + ), self._interpolation_edge, ] diff --git a/data_prototype/line.py b/data_prototype/line.py index 8805e8b..f7c01ff 100644 --- a/data_prototype/line.py +++ b/data_prototype/line.py @@ -18,7 +18,7 @@ def __init__(self, container, edges=None, **kwargs): scalar = Desc((), "display") # ... this needs thinking... - edges = [ + default_edges = [ CoordinateEdge.from_coords("xycoords", {"x": "auto", "y": "auto"}, "data"), CoordinateEdge.from_coords("color", {"color": Desc(())}, "display"), CoordinateEdge.from_coords("linewidth", {"linewidth": Desc(())}, "display"), @@ -45,7 +45,7 @@ def __init__(self, container, edges=None, **kwargs): DefaultEdge.from_default_value("mew_def", "markeredgewidth", scalar, 1), DefaultEdge.from_default_value("marker_def", "marker", scalar, "None"), ] - self._graph = self._graph + Graph(edges) + self._graph = self._graph + Graph(default_edges) # Currently ignoring: # - cap/join style # - url diff --git a/examples/2Dfunc.py b/examples/2Dfunc.py index deaad36..883b932 100644 --- a/examples/2Dfunc.py +++ b/examples/2Dfunc.py @@ -10,7 +10,8 @@ import matplotlib.pyplot as plt import numpy as np -from data_prototype.wrappers import ImageWrapper +from data_prototype.artist import CompatibilityAxes +from data_prototype.image import Image from data_prototype.containers import FuncContainer from matplotlib.colors import Normalize @@ -19,8 +20,8 @@ fc = FuncContainer( {}, xyfuncs={ - "xextent": ((2,), lambda x, y: [x[0], x[-1]]), - "yextent": ((2,), lambda x, y: [y[0], y[-1]]), + "x": ((2,), lambda x, y: [x[0], x[-1]]), + "y": ((2,), lambda x, y: [y[0], y[-1]]), "image": ( ("N", "M"), lambda x, y: np.sin(x).reshape(1, -1) * np.cos(y).reshape(-1, 1), @@ -28,11 +29,14 @@ }, ) norm = Normalize(vmin=-1, vmax=1) -im = ImageWrapper(fc, norm=norm) +im = Image(fc, norm=norm) + +fig, nax = plt.subplots() +ax = CompatibilityAxes(nax) +nax.add_artist(ax) -fig, ax = plt.subplots() ax.add_artist(im) ax.set_xlim(-5, 5) ax.set_ylim(-5, 5) -fig.colorbar(im) +# fig.colorbar(im, ax=nax) plt.show() diff --git a/examples/mapped.py b/examples/mapped.py index 85cd636..588b123 100644 --- a/examples/mapped.py +++ b/examples/mapped.py @@ -11,14 +11,14 @@ import numpy as np from matplotlib.colors import Normalize +from matplotlib.font_manager import FontProperties -from data_prototype.wrappers import FormattedText -from data_prototype.artist import CompatibilityArtist as CA +from data_prototype.artist import CompatibilityAxes from data_prototype.line import Line from data_prototype.containers import ArrayContainer from data_prototype.description import Desc -from data_prototype.conversion_node import FunctionConversionNode from data_prototype.conversion_edge import FuncEdge +from data_prototype.text import Text cmap = plt.colormaps["viridis"] @@ -49,19 +49,41 @@ ), ] -text_converter = FunctionConversionNode.from_funcs( - { - "text": lambda j, cat: f"index={j[()]} class={cat!r}", - "y": lambda j: j, - "x": lambda x: 2 * np.pi, - }, -) +text_edges = [ + FuncEdge.from_func( + "text", + lambda j, cat: f"index={j[()]} class={cat!r}", + {"j": Desc((), "auto"), "cat": Desc((), "auto")}, + {"text": Desc((), "display")}, + ), + FuncEdge.from_func( + "y", + lambda j: j, + {"j": Desc((), "auto")}, + {"y": Desc((), "data")}, + ), + FuncEdge.from_func( + "x", + lambda: 2 * np.pi, + {}, + {"x": Desc((), "data")}, + ), + FuncEdge.from_func( + "color", + lambda: (0, 0, 0, 1), + {}, + {"color": Desc((4,), "rgba")}, + ), +] th = np.linspace(0, 2 * np.pi, 128) delta = np.pi / 9 -fig, ax = plt.subplots() +fig, nax = plt.subplots() + +ax = CompatibilityAxes(nax) +nax.add_artist(ax) for j in range(10): ac = ArrayContainer( @@ -74,20 +96,23 @@ } ) ax.add_artist( - CA( - Line( - ac, - line_edges, - ) + Line( + ac, + line_edges, ) ) ax.add_artist( - FormattedText( + Text( ac, - text_converter, + text_edges, x=2 * np.pi, - ha="right", - bbox={"facecolor": "gray", "alpha": 0.5}, + # ha="right", + # bbox={"facecolor": "gray", "alpha": 0.5}, + antialiased=False, + fontproperties=FontProperties(), + rotation=0, + alpha=1, + usetex=False, ) ) ax.set_xlim(0, np.pi * 2) diff --git a/examples/mulivariate_cmap.py b/examples/mulivariate_cmap.py index c00b709..8b33ca8 100644 --- a/examples/mulivariate_cmap.py +++ b/examples/mulivariate_cmap.py @@ -11,9 +11,11 @@ import matplotlib.pyplot as plt import numpy as np -from data_prototype.wrappers import ImageWrapper +from data_prototype.image import Image +from data_prototype.artist import CompatibilityAxes +from data_prototype.description import Desc from data_prototype.containers import FuncContainer -from data_prototype.conversion_node import FunctionConversionNode +from data_prototype.conversion_edge import FuncEdge from matplotlib.colors import hsv_to_rgb @@ -35,15 +37,24 @@ def image_nu(image): fc = FuncContainer( {}, xyfuncs={ - "xextent": ((2,), lambda x, y: [x[0], x[-1]]), - "yextent": ((2,), lambda x, y: [y[0], y[-1]]), + "x": ((2,), lambda x, y: [x[0], x[-1]]), + "y": ((2,), lambda x, y: [y[0], y[-1]]), "image": (("N", "M", 2), func), }, ) -im = ImageWrapper(fc, FunctionConversionNode.from_funcs({"image": image_nu})) +image_edges = FuncEdge.from_func( + "image", + image_nu, + {"image": Desc(("M", "N", 2), "auto")}, + {"image": Desc(("M", "N", 3), "rgb")}, +) + +im = Image(fc, [image_edges]) -fig, ax = plt.subplots() +fig, nax = plt.subplots() +ax = CompatibilityAxes(nax) +nax.add_artist(ax) ax.add_artist(im) ax.set_xlim(-5, 5) ax.set_ylim(-5, 5)