11
11
DEFAULT_RENDER_DEPTH = 5
12
12
13
13
class _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
+ """
14
20
def __init__ (
15
21
self ,
16
22
artist : Artist ,
@@ -79,15 +85,20 @@ def do_3d_projection(self) -> float:
79
85
return res
80
86
81
87
def _view_from_pickle (builder , args ):
88
+ """
89
+ PRIVATE: Construct a View wrapper axes given an axes builder and class.
90
+ """
82
91
res = builder (* args )
83
92
res .__class__ = view_wrapper (type (res ))
84
93
return res
85
94
95
+ # Cache classes so grabbing the same type twice leads to actually getting the
96
+ # same type (and type comparisons work).
86
97
@functools .lru_cache (None )
87
98
def view_wrapper (axes_class : Type [Axes ]) -> Type [Axes ]:
88
99
"""
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
91
102
within the same Figure.
92
103
93
104
Parameters
@@ -97,9 +108,9 @@ def view_wrapper(axes_class: Type[Axes]) -> Type[Axes]:
97
108
98
109
Returns
99
110
-------
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...
103
114
"""
104
115
@docstring .interpd
105
116
class View (axes_class ):
@@ -155,7 +166,7 @@ def __init__(
155
166
156
167
Returns
157
168
-------
158
- ViewAxes
169
+ View
159
170
The new zoom view axes instance...
160
171
"""
161
172
super ().__init__ (axes_to_view .figure , * args , ** kwargs )
@@ -240,6 +251,88 @@ def draw(self, renderer: RendererBase = None):
240
251
self .__renderer = None
241
252
self .figure ._current_render_depth -= 1
242
253
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
+
243
336
def get_linescaling (self ) -> bool :
244
337
"""
245
338
Get if line width scaling is enabled.
@@ -264,6 +357,32 @@ def set_linescaling(self, value: bool):
264
357
"""
265
358
self .__scale_lines = value
266
359
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
+
267
386
def __reduce__ (self ):
268
387
builder , args = super ().__reduce__ ()[:2 ]
269
388
@@ -297,6 +416,56 @@ def from_axes(
297
416
render_depth : int = DEFAULT_RENDER_DEPTH ,
298
417
filter_function : Optional [Callable [[Artist ], bool ]] = None
299
418
) -> 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
+
300
469
axes .__class__ = cls
301
470
axes ._init_vars (
302
471
axes_to_view , image_interpolation ,
0 commit comments