@@ -106,6 +106,12 @@ def __post_init__(self):
106106 self .filter_set = set (self .filter_set )
107107 self .scale_lines = bool (self .scale_lines )
108108
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+ ...
109115
110116# Cache classes so grabbing the same type twice leads to actually getting the
111117# same type (and type comparisons work).
@@ -127,8 +133,11 @@ def view_wrapper(axes_class: Type[Axes]) -> Type[Axes]:
127133 The view axes wrapper for a given axes class, capable of displaying
128134 another axes contents...
129135 """
136+ if (issubclass (axes_class , Axes ) and issubclass (axes_class , __ViewType )):
137+ return axes_class
138+
130139 @docstring .interpd
131- class View (axes_class ):
140+ class View (axes_class , __ViewType ):
132141 """
133142 An axes which automatically displays elements of another axes. Does not
134143 require Artists to be plotted twice.
@@ -151,10 +160,10 @@ def __init__(
151160 Additional arguments to be passed to the Axes class this
152161 ViewAxes wraps.
153162
154- render_depth: int, positive, defaults to 10
163+ render_depth: int, positive, defaults to 5
155164 The number of recursive draws allowed for this view, this can
156165 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 .
158167
159168 **kwargs
160169 Other optional keyword arguments supported by the Axes
@@ -171,10 +180,12 @@ def __init__(
171180 self ._init_vars (render_depth )
172181
173182 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" , {})
176185 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+ )
178189 self .set_max_render_depth (render_depth )
179190 # The current render depth is stored in the figure, so the number
180191 # of recursive draws is even in the case of multiple axes drawing
@@ -297,11 +308,14 @@ def view_specifications(self) -> Dict[Axes, ViewSpecification]:
297308 """
298309 return self .__view_specs
299310
311+ # Shortcut for easier access...
312+ view_specs = view_specifications
313+
300314 @classmethod
301315 def from_axes (
302316 cls ,
303317 axes : Axes ,
304- render_depth : int = DEFAULT_RENDER_DEPTH
318+ render_depth : Optional [ int ] = None
305319 ) -> Axes :
306320 """
307321 Convert an Axes into a View in-place. This is used by public
@@ -314,10 +328,11 @@ def from_axes(
314328 axes: Axes
315329 The axes to convert to a view wrapping the same axes type.
316330
317- render_depth: int, positive, defaults to 10
331+ render_depth: optional int, positive, defaults to None
318332 The number of recursive draws allowed for this view, this can
319333 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.
321336
322337 Returns
323338 -------
@@ -329,18 +344,24 @@ def from_axes(
329344 ------
330345 TypeError
331346 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.
333348 """
349+ if (isinstance (axes , cls )):
350+ if (render_depth is not None ):
351+ axes .set_max_render_depth (render_depth )
352+ return axes
353+
334354 if (type (axes ) != axes_class ):
335355 raise TypeError (
336356 f"Can't convert { type (axes ).__name__ } to { cls .__name__ } "
337357 )
338358
339- if (isinstance (axes , cls )):
340- return axes
341-
342359 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+ )
344365 return axes
345366
346367 View .__name__ = f"{ View .__name__ } [{ axes_class .__name__ } ]"
0 commit comments