-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path__init__.py
More file actions
193 lines (161 loc) · 6.15 KB
/
__init__.py
File metadata and controls
193 lines (161 loc) · 6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
from typing import Optional, Iterable, Type, Union
from matplotlib.artist import Artist
from matplotlib.axes import Axes
from matplotlib.transforms import Transform
from matplotview._view_axes import (
view_wrapper,
ViewSpecification,
DEFAULT_RENDER_DEPTH
)
from matplotview._docs import dynamic_doc_string, get_interpolation_list_str
__all__ = ["view", "stop_viewing", "inset_zoom_axes"]
@dynamic_doc_string(
render_depth=DEFAULT_RENDER_DEPTH,
interp_list=get_interpolation_list_str()
)
def view(
axes: Axes,
axes_to_view: Axes,
image_interpolation: str = "nearest",
render_depth: Optional[int] = None,
filter_set: Optional[Iterable[Union[Type[Artist], Artist]]] = None,
scale_lines: bool = True
) -> Axes:
"""
Convert an axes into a view of another axes, displaying the contents of
the second axes. If this axes is already viewing the passed axes (This
function is called twice with the same axes arguments) this function
will update the settings of the viewing instead of creating a new view.
Parameters
----------
axes: Axes
The axes to turn into a view of another axes.
axes_to_view: Axes
The axes to display the contents of in the first axes, the 'viewed'
axes.
image_interpolation: string, default of '{image_interpolation}'
The image interpolation method to use when displaying scaled images
from the axes being viewed. Defaults to '{image_interpolation}'.
Supported options are {interp_list}.
render_depth: optional int, positive, defaults to None
The number of recursive draws allowed for this view, this can happen
if the view is a child of the axes (such as an inset axes) or if
two views point at each other. If None, uses the default render depth
of {render_depth}, unless the axes passed is already a view axes, in
which case the render depth the view already has will be used.
filter_set: Iterable[Union[Type[Artist], Artist]] or None
An optional filter set, which can be used to select what artists
are drawn by the view. Any artists or artist types in the set are not
drawn.
scale_lines: bool, defaults to {scale_lines}
Specifies if lines should be drawn thicker based on scaling in the
view.
Returns
-------
axes
The modified `~.axes.Axes` instance which is now a view.
The modification occurs in-place.
See Also
--------
matplotview.stop_viewing: Delete or stop an already constructed view.
matplotview.inset_zoom_axes: Convenience method for creating inset axes
that are views of the parent axes.
"""
view_obj = view_wrapper(type(axes)).from_axes(axes, render_depth)
view_obj.view_specifications[axes_to_view] = ViewSpecification(
image_interpolation,
filter_set,
scale_lines
)
return view_obj
def stop_viewing(view: Axes, axes_of_viewing: Axes) -> Axes:
"""
Terminate the viewing of a specified axes.
Parameters
----------
view: Axes
The axes that is currently viewing the `axes_of_viewing`...
axes_of_viewing: Axes
The axes that the view should stop viewing.
Returns
-------
view
The view, which has now been modified in-place.
Raises
------
AttributeError
If the provided `axes_of_viewing` is not actually being
viewed by the specified view.
See Also
--------
matplotview.view: To create views.
"""
view = view_wrapper(type(view)).from_axes(view)
del view.view_specifications[axes_of_viewing]
return view
@dynamic_doc_string(
render_depth=DEFAULT_RENDER_DEPTH,
interp_list=get_interpolation_list_str()
)
def inset_zoom_axes(
axes: Axes,
bounds: Iterable,
*,
image_interpolation: str = "nearest",
render_depth: Optional[int] = None,
filter_set: Optional[Iterable[Union[Type[Artist], Artist]]] = None,
scale_lines: bool = True,
transform: Transform = None,
zorder: int = 5,
**kwargs
) -> Axes:
"""
Add a child inset Axes to an Axes, which automatically plots
artists contained within the parent Axes.
Parameters
----------
axes: Axes
The axes to insert a new inset zoom axes inside.
bounds: [x0, y0, width, height]
Lower-left corner of inset Axes, and its width and height.
transform: `.Transform`
Defaults to `ax.transAxes`, i.e. the units of *rect* are in
Axes-relative coordinates.
zorder: number
Defaults to {zorder} (same as `.Axes.legend`). Adjust higher or lower
to change whether it is above or below data plotted on the
parent Axes.
image_interpolation: string
Supported options are {interp_list}. The default value is
'{image_interpolation}'. This determines the interpolation
used when attempting to render a zoomed version of an image.
render_depth: optional int, positive, defaults to None
The number of recursive draws allowed for this view, this can happen
if the view is a child of the axes (such as an inset axes) or if
two views point at each other. If None, uses the default render depth
of {render_depth}, unless the axes passed is already a view axes,
in which case the render depth the view already has will be used.
filter_set: Iterable[Union[Type[Artist], Artist]] or None
An optional filter set, which can be used to select what artists
are drawn by the view. Any artists or artist types in the set are not
drawn.
scale_lines: bool, defaults to {scale_lines}
Specifies if lines should be drawn thicker based on scaling in the
view.
**kwargs
Other keyword arguments are passed on to the child `.Axes`.
Returns
-------
ax
The created `~.axes.Axes` instance.
See Also
--------
matplotview.view: For creating views in generalized cases.
"""
inset_ax = axes.inset_axes(
bounds, transform=transform, zorder=zorder, **kwargs
)
return view(
inset_ax, axes, image_interpolation,
render_depth, filter_set, scale_lines
)