@@ -106,6 +106,12 @@ def __post_init__(self):
106
106
self .filter_set = set (self .filter_set )
107
107
self .scale_lines = bool (self .scale_lines )
108
108
109
+ class __ViewType :
110
+ """
111
+ PRIVATE: A simple identifier class for identifying view types, a view
112
+ will inherit from the axes class it is wrapping and this type...
113
+ """
114
+ ...
109
115
110
116
# Cache classes so grabbing the same type twice leads to actually getting the
111
117
# same type (and type comparisons work).
@@ -127,8 +133,11 @@ def view_wrapper(axes_class: Type[Axes]) -> Type[Axes]:
127
133
The view axes wrapper for a given axes class, capable of displaying
128
134
another axes contents...
129
135
"""
136
+ if (issubclass (axes_class , Axes ) and issubclass (axes_class , __ViewType )):
137
+ return axes_class
138
+
130
139
@docstring .interpd
131
- class View (axes_class ):
140
+ class View (axes_class , __ViewType ):
132
141
"""
133
142
An axes which automatically displays elements of another axes. Does not
134
143
require Artists to be plotted twice.
@@ -151,10 +160,10 @@ def __init__(
151
160
Additional arguments to be passed to the Axes class this
152
161
ViewAxes wraps.
153
162
154
- render_depth: int, positive, defaults to 10
163
+ render_depth: int, positive, defaults to 5
155
164
The number of recursive draws allowed for this view, this can
156
165
happen if the view is a child of the axes (such as an inset
157
- axes) or if two views point at each other. Defaults to 10 .
166
+ axes) or if two views point at each other. Defaults to 5 .
158
167
159
168
**kwargs
160
169
Other optional keyword arguments supported by the Axes
@@ -171,10 +180,12 @@ def __init__(
171
180
self ._init_vars (render_depth )
172
181
173
182
def _init_vars (self , render_depth : int = DEFAULT_RENDER_DEPTH ):
174
- # Initialize the view specs set ...
175
- self .__view_specs = {}
183
+ # Initialize the view specs dict ...
184
+ self .__view_specs = getattr ( self , "__view_specs" , {})
176
185
self .__renderer = None
177
- self .__max_render_depth = DEFAULT_RENDER_DEPTH
186
+ self .__max_render_depth = getattr (
187
+ self , "__max_render_depth" , DEFAULT_RENDER_DEPTH
188
+ )
178
189
self .set_max_render_depth (render_depth )
179
190
# The current render depth is stored in the figure, so the number
180
191
# of recursive draws is even in the case of multiple axes drawing
@@ -297,11 +308,14 @@ def view_specifications(self) -> Dict[Axes, ViewSpecification]:
297
308
"""
298
309
return self .__view_specs
299
310
311
+ # Shortcut for easier access...
312
+ view_specs = view_specifications
313
+
300
314
@classmethod
301
315
def from_axes (
302
316
cls ,
303
317
axes : Axes ,
304
- render_depth : int = DEFAULT_RENDER_DEPTH
318
+ render_depth : Optional [ int ] = None
305
319
) -> Axes :
306
320
"""
307
321
Convert an Axes into a View in-place. This is used by public
@@ -314,10 +328,11 @@ def from_axes(
314
328
axes: Axes
315
329
The axes to convert to a view wrapping the same axes type.
316
330
317
- render_depth: int, positive, defaults to 10
331
+ render_depth: optional int, positive, defaults to None
318
332
The number of recursive draws allowed for this view, this can
319
333
happen if the view is a child of the axes (such as an inset
320
- axes) or if two views point at each other. Defaults to 10.
334
+ axes) or if two views point at each other. If none, use the
335
+ default value (5) if the render depth is not already set.
321
336
322
337
Returns
323
338
-------
@@ -329,18 +344,24 @@ def from_axes(
329
344
------
330
345
TypeError
331
346
If the provided axes to convert has an Axes type which does
332
- not match the axes class this view type wraps.ss
347
+ not match the axes class this view type wraps.
333
348
"""
349
+ if (isinstance (axes , cls )):
350
+ if (render_depth is not None ):
351
+ axes .set_max_render_depth (render_depth )
352
+ return axes
353
+
334
354
if (type (axes ) != axes_class ):
335
355
raise TypeError (
336
356
f"Can't convert { type (axes ).__name__ } to { cls .__name__ } "
337
357
)
338
358
339
- if (isinstance (axes , cls )):
340
- return axes
341
-
342
359
axes .__class__ = cls
343
- axes ._init_vars (render_depth )
360
+ axes ._init_vars (
361
+ DEFAULT_RENDER_DEPTH
362
+ if (render_depth is None )
363
+ else render_depth
364
+ )
344
365
return axes
345
366
346
367
View .__name__ = f"{ View .__name__ } [{ axes_class .__name__ } ]"
0 commit comments