|
7 | 7 | """
|
8 | 8 |
|
9 | 9 | import numpy as np
|
| 10 | +from collections import defaultdict |
10 | 11 |
|
11 | 12 | import matplotlib.pyplot as plt
|
12 | 13 | import matplotlib.markers as mmarkers
|
13 | 14 |
|
| 15 | +from data_prototype.artist import CompatibilityAxes |
14 | 16 | from data_prototype.containers import ArrayContainer
|
15 |
| -from data_prototype.conversion_node import DelayedConversionNode |
| 17 | +from data_prototype.conversion_edge import FuncEdge |
16 | 18 |
|
17 |
| -from data_prototype.wrappers import PathCollectionWrapper |
| 19 | +from data_prototype.line import Line |
18 | 20 |
|
19 | 21 | import pint
|
20 | 22 |
|
|
23 | 25 |
|
24 | 26 | marker_obj = mmarkers.MarkerStyle("o")
|
25 | 27 |
|
| 28 | + |
| 29 | +coords = defaultdict(lambda: "auto") |
| 30 | +coords["x"] = coords["y"] = "units" |
26 | 31 | cont = ArrayContainer(
|
| 32 | + coords, |
27 | 33 | x=np.array([0, 1, 2]) * ureg.m,
|
28 | 34 | y=np.array([1, 4, 2]) * ureg.m,
|
29 | 35 | paths=np.array([marker_obj.get_path()]),
|
|
32 | 38 | facecolors=np.array(["C3"]),
|
33 | 39 | )
|
34 | 40 |
|
35 |
| -fig, ax = plt.subplots() |
| 41 | +fig, nax = plt.subplots() |
| 42 | +ax = CompatibilityAxes(nax) |
| 43 | +nax.add_artist(ax) |
36 | 44 | ax.set_xlim(-0.5, 7)
|
37 | 45 | ax.set_ylim(0, 5)
|
38 | 46 |
|
39 |
| -# DelayedConversionNode is used to identify the keys which undergo unit transformations |
40 |
| -# The actual method which does conversions in this example is added by the |
41 |
| -# `Axis`/`Axes`, but `PathCollectionWrapper` does not natively interact with the units. |
42 |
| -xconv = DelayedConversionNode.from_keys(("x",), converter_key="xunits") |
43 |
| -yconv = DelayedConversionNode.from_keys(("y",), converter_key="yunits") |
44 |
| -lw = PathCollectionWrapper(cont, [xconv, yconv], offset_transform=ax.transData) |
| 47 | +xconv = FuncEdge.from_func("xconv", lambda x, xunits: x.to(xunits), "units", "data") |
| 48 | +yconv = FuncEdge.from_func("yconv", lambda y, yunits: y.to(yunits), "units", "data") |
| 49 | +lw = Line(cont, [xconv, yconv]) |
45 | 50 | ax.add_artist(lw)
|
46 |
| -ax.xaxis.set_units(ureg.feet) |
47 |
| -ax.yaxis.set_units(ureg.m) |
| 51 | +nax.xaxis.set_units(ureg.feet) |
| 52 | +nax.yaxis.set_units(ureg.m) |
| 53 | + |
48 | 54 | plt.show()
|
0 commit comments