Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b905720

Browse files
committed
WIP, lines containers decorator
1 parent 6e95994 commit b905720

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

lib/matplotlib/_containers.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from mpl_data_containers.description import Desc, desc_like
2+
from mpl_data_containers.graph import Graph
3+
from mpl_data_containers.conversion_edge import TransformEdge
4+
5+
6+
def containerize_draw(draw_func):
7+
def draw(self, renderer, *, graph=None):
8+
if graph is None:
9+
graph = Graph([])
10+
11+
ax = self.axes
12+
if ax is None:
13+
implicit_graph = Graph([])
14+
else:
15+
desc: Desc = Desc(("N",), coordinates="data")
16+
xy: dict[str, Desc] = {"x": desc, "y": desc}
17+
implicit_graph = Graph(
18+
[
19+
TransformEdge(
20+
"data",
21+
xy,
22+
desc_like(xy, coordinates="axes"),
23+
transform=ax.transData - ax.transAxes,
24+
),
25+
TransformEdge(
26+
"axes",
27+
desc_like(xy, coordinates="axes"),
28+
desc_like(xy, coordinates="display"),
29+
transform=ax.transAxes,
30+
),
31+
],
32+
aliases=(("parent", "axes"),),
33+
)
34+
35+
return draw_func(self, renderer, graph=graph+implicit_graph)
36+
37+
return draw

lib/matplotlib/lines.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from .path import Path
1919
from .transforms import Bbox, BboxTransformTo, TransformedPath
2020
from ._enums import JoinStyle, CapStyle
21+
from ._containers import containerize_draw
2122

2223
# Imported here for backward compatibility, even though they don't
2324
# really belong.
@@ -424,6 +425,7 @@ def __init__(self, xdata, ydata, *,
424425
self._transformed_path = None
425426
self._subslice = False
426427
self._x_filled = None # used in subslicing; only x is needed
428+
self._container = None
427429

428430
self.set_data(xdata, ydata)
429431

@@ -744,7 +746,8 @@ def set_transform(self, t):
744746
super().set_transform(t)
745747

746748
@allow_rasterization
747-
def draw(self, renderer):
749+
@containerize_draw
750+
def draw(self, renderer, *, graph=None):
748751
# docstring inherited
749752

750753
if not self.get_visible():

0 commit comments

Comments
 (0)