Skip to content

Commit 058ae26

Browse files
Add support for views for multiple axes.
1 parent 7f69ae1 commit 058ae26

File tree

4 files changed

+131
-247
lines changed

4 files changed

+131
-247
lines changed

matplotview/__init__.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
from typing import Callable, Optional, Iterable
1+
from typing import Optional, Iterable, Type, Union
22
from matplotlib.artist import Artist
33
from matplotlib.axes import Axes
4-
from matplotview._view_axes import view_wrapper, DEFAULT_RENDER_DEPTH
4+
from matplotview._view_axes import view_wrapper, ViewSpecification, DEFAULT_RENDER_DEPTH
5+
6+
__all__ = ["view", "inset_zoom_axes"]
57

68
def view(
79
axes: Axes,
810
axes_to_view: Axes,
911
image_interpolation: str = "nearest",
1012
render_depth: int = DEFAULT_RENDER_DEPTH,
11-
filter_function: Optional[Callable[[Artist], bool]] = None
13+
filter_set: Optional[Iterable[Union[Type[Artist], Artist]]] = None,
14+
scale_lines: bool = True
1215
) -> Axes:
1316
"""
1417
Convert an axes into a view of another axes, displaying the contents of
@@ -36,15 +39,21 @@ def view(
3639
if the view is a child of the axes (such as an inset axes) or if
3740
two views point at each other. Defaults to 5.
3841
39-
filter_function: callable(Artist) -> bool or None
40-
An optional filter function, which can be used to select what artists
41-
are drawn by the view. If the function returns True, the element is
42-
drawn, otherwise it isn't. Defaults to None, or drawing all artists.
42+
filter_set: Iterable[Union[Type[Artist], Artist]] or None
43+
An optional filter set, which can be used to select what artists
44+
are drawn by the view. Any artists types in the set are not drawn.
45+
46+
scale_lines: bool, defaults to True
47+
Specifies if lines should be drawn thicker based on scaling in the
48+
view.
4349
"""
44-
return view_wrapper(type(axes)).from_axes(
45-
axes, axes_to_view, image_interpolation,
46-
render_depth, filter_function
50+
view_obj = view_wrapper(type(axes)).from_axes(axes, render_depth)
51+
view_obj.view_specifications[axes_to_view] = ViewSpecification(
52+
image_interpolation,
53+
filter_set,
54+
scale_lines
4755
)
56+
return view_obj
4857

4958

5059
def inset_zoom_axes(
@@ -53,7 +62,8 @@ def inset_zoom_axes(
5362
*,
5463
image_interpolation="nearest",
5564
render_depth: int = DEFAULT_RENDER_DEPTH,
56-
filter_function: Optional[Callable[[Artist], bool]] = None,
65+
filter_set: Optional[Iterable[Union[Type[Artist], Artist]]] = None,
66+
scale_lines: bool = True,
5767
transform=None,
5868
zorder=5,
5969
**kwargs
@@ -92,10 +102,13 @@ def inset_zoom_axes(
92102
if the view is a child of the axes (such as an inset axes) or if
93103
two views point at each other. Defaults to 5.
94104
95-
filter_function: callable(Artist) -> bool or None
96-
An optional filter function, which can be used to select what artists
97-
are drawn by the view. If the function returns True, the element is
98-
drawn, otherwise it isn't. Defaults to None, or drawing all artists.
105+
filter_set: Iterable[Union[Type[Artist], Artist]] or None
106+
An optional filter set, which can be used to select what artists
107+
are drawn by the view. Any artists types in the set are not drawn.
108+
109+
scale_lines: bool, defaults to True
110+
Specifies if lines should be drawn thicker based on scaling in the
111+
view.
99112
100113
**kwargs
101114
Other keyword arguments are passed on to the child `.Axes`.
@@ -114,5 +127,5 @@ def inset_zoom_axes(
114127
)
115128
return view(
116129
inset_ax, axes, image_interpolation,
117-
render_depth, filter_function
130+
render_depth, filter_set, scale_lines
118131
)

0 commit comments

Comments
 (0)