1111DEFAULT_RENDER_DEPTH = 5
1212
1313class _BoundRendererArtist :
14+ """
15+ Provides a temporary wrapper around a given artist, inheriting its
16+ attributes and values, while overloading draw to use a fixed
17+ TransformRenderer. This is used to render an artist to a view without
18+ having to implement a new draw for every Axes type.
19+ """
1420 def __init__ (
1521 self ,
1622 artist : Artist ,
@@ -79,15 +85,20 @@ def do_3d_projection(self) -> float:
7985 return res
8086
8187def _view_from_pickle (builder , args ):
88+ """
89+ PRIVATE: Construct a View wrapper axes given an axes builder and class.
90+ """
8291 res = builder (* args )
8392 res .__class__ = view_wrapper (type (res ))
8493 return res
8594
95+ # Cache classes so grabbing the same type twice leads to actually getting the
96+ # same type (and type comparisons work).
8697@functools .lru_cache (None )
8798def view_wrapper (axes_class : Type [Axes ]) -> Type [Axes ]:
8899 """
89- Construct a ViewAxes , which subclasses, or wraps a specific Axes subclass.
90- A ViewAxes can be configured to display the contents of another Axes
100+ Construct a View axes , which subclasses, or wraps a specific Axes subclass.
101+ A View axes can be configured to display the contents of another Axes
91102 within the same Figure.
92103
93104 Parameters
@@ -97,9 +108,9 @@ def view_wrapper(axes_class: Type[Axes]) -> Type[Axes]:
97108
98109 Returns
99110 -------
100- ViewAxes :
101- The view axes wrapper for a given axes class, capable of display
102- other axes contents...
111+ View[axes_class] :
112+ The view axes wrapper for a given axes class, capable of displaying
113+ another axes contents...
103114 """
104115 @docstring .interpd
105116 class View (axes_class ):
@@ -155,7 +166,7 @@ def __init__(
155166
156167 Returns
157168 -------
158- ViewAxes
169+ View
159170 The new zoom view axes instance...
160171 """
161172 super ().__init__ (axes_to_view .figure , * args , ** kwargs )
@@ -240,6 +251,88 @@ def draw(self, renderer: RendererBase = None):
240251 self .__renderer = None
241252 self .figure ._current_render_depth -= 1
242253
254+ def get_axes_to_view (self ) -> Axes :
255+ """
256+ Get the axes this view will display.
257+
258+ Returns
259+ -------
260+ Axes
261+ The axes being viewed.
262+ """
263+ return self .__view_axes
264+
265+ def set_axes_to_view (self , ax : Axes ):
266+ """
267+ Set the axes this view will display.
268+
269+ Parameters
270+ ----------
271+ ax: Axes
272+ The new axes to be viewed.
273+ """
274+ self .__view_axes = ax
275+
276+ def get_image_interpolation (self ) -> str :
277+ """
278+ Get the current image interpolation used for rendering views of
279+ images. Supported options are 'antialiased', 'nearest', 'bilinear',
280+ 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming',
281+ 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel',
282+ 'mitchell', 'sinc', 'lanczos', or 'none'. The default value is
283+ 'nearest'.
284+
285+ Returns
286+ -------
287+ string
288+ The current image interpolation used when rendering views of
289+ images in this view axes.
290+ """
291+ return self .__image_interpolation
292+
293+ def set_image_interpolation (self , val : str ):
294+ """
295+ Set the current image interpolation used for rendering views of
296+ images. Supported options are 'antialiased', 'nearest', 'bilinear',
297+ 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming',
298+ 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel',
299+ 'mitchell', 'sinc', 'lanczos', or 'none'. The default value is
300+ 'nearest'.
301+
302+ Parameters
303+ ----------
304+ val: string
305+ A new image interpolation mode.
306+ """
307+ self .__image_interpolation = val
308+
309+ def get_max_render_depth (self ) -> int :
310+ """
311+ Get the max recursive rendering depth for this view axes.
312+
313+ Returns
314+ -------
315+ int
316+ A positive non-zero integer, the number of recursive redraws
317+ this view axes will allow.
318+ """
319+ return self .__max_render_depth
320+
321+ def set_max_render_depth (self , val : int ):
322+ """
323+ Set the max recursive rendering depth for this view axes.
324+
325+ Parameters
326+ ----------
327+ val: int
328+ The number of recursive draws of views this view axes will
329+ allow. Zero and negative values are invalid, and will raise a
330+ ValueError.
331+ """
332+ if (val <= 0 ):
333+ raise ValueError (f"Render depth must be positive, not { val } ." )
334+ self .__max_render_depth = val
335+
243336 def get_linescaling (self ) -> bool :
244337 """
245338 Get if line width scaling is enabled.
@@ -264,6 +357,32 @@ def set_linescaling(self, value: bool):
264357 """
265358 self .__scale_lines = value
266359
360+ def get_filter_function (self ) -> Optional [Callable [[Artist ], bool ]]:
361+ """
362+ Get the current artist filtering function.
363+
364+ Returns
365+ -------
366+ function, optional
367+ The filter function, which accepts an artist and returns true
368+ if it should be drawn, otherwise false. Can also be none,
369+ meaning all artists should be drawn from the other axes.
370+ """
371+ return self .__filter_function
372+
373+ def set_filter_function (self , f : Optional [Callable [[Artist ], bool ]]):
374+ """
375+ Set the artist filtering function.
376+
377+ Returns
378+ -------
379+ f: function, optional
380+ A filter function, which accepts an artist and returns true
381+ if it should be drawn, otherwise false. Can also be set to
382+ None, meaning all artists should be drawn from the other axes.
383+ """
384+ self .__filter_function = f
385+
267386 def __reduce__ (self ):
268387 builder , args = super ().__reduce__ ()[:2 ]
269388
@@ -297,6 +416,56 @@ def from_axes(
297416 render_depth : int = DEFAULT_RENDER_DEPTH ,
298417 filter_function : Optional [Callable [[Artist ], bool ]] = None
299418 ) -> Axes :
419+ """
420+ Convert an Axes into a View in-place. This is used by public
421+ APIs to construct views, and using this method directly
422+ is not recommended. Instead use `view` which resolves types
423+ automatically.
424+
425+ Parameters
426+ ----------
427+ axes: Axes
428+ The axes to convert to a view wrapping the same axes type.
429+
430+ axes_to_view: `~.axes.Axes`
431+ The axes to create a view of.
432+
433+ image_interpolation: string
434+ Supported options are 'antialiased', 'nearest', 'bilinear',
435+ 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming',
436+ 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel',
437+ 'mitchell', 'sinc', 'lanczos', or 'none'. The default value is
438+ 'nearest'. This determines the interpolation used when
439+ attempting to render a view of an image.
440+
441+ render_depth: int, positive, defaults to 10
442+ The number of recursive draws allowed for this view, this can
443+ happen if the view is a child of the axes (such as an inset
444+ axes) or if two views point at each other. Defaults to 10.
445+
446+ filter_function: callable(Artist) -> bool or None
447+ An optional filter function, which can be used to select what
448+ artists are drawn by the view. If the function returns True,
449+ the element is drawn, otherwise it isn't. Defaults to None,
450+ or drawing all artists.
451+
452+ Returns
453+ -------
454+ View
455+ The same axes passed in, which is now a View type which wraps
456+ the axes original type (View[axes_original_class]).
457+
458+ Raises
459+ ------
460+ TypeError
461+ If the provided axes to convert has an Axes type which does
462+ not match the axes class this view type wraps.ss
463+ """
464+ if (type (axes ) != axes_class ):
465+ raise TypeError (
466+ f"Can't convert { type (axes ).__name__ } to { cls .__name__ } "
467+ )
468+
300469 axes .__class__ = cls
301470 axes ._init_vars (
302471 axes_to_view , image_interpolation ,
0 commit comments