@@ -147,9 +147,11 @@ def __init__(self, *args, **kwargs):
147
147
148
148
def set_figure (self , fig ):
149
149
"""
150
- Set the figure
150
+ Set the `.Figure` for the `.OffsetBox` and all its children.
151
151
152
- accepts a class:`~matplotlib.figure.Figure` instance
152
+ Parameters
153
+ ----------
154
+ fig : `~matplotlib.figure.Figure`
153
155
"""
154
156
martist .Artist .set_figure (self , fig )
155
157
for c in self .get_children ():
@@ -164,6 +166,29 @@ def axes(self, ax):
164
166
c .axes = ax
165
167
166
168
def contains (self , mouseevent ):
169
+ """
170
+ Delegate the mouse event contains-check to the children.
171
+
172
+ As a container, the `.OffsetBox` does not respond itself to
173
+ mouseevents.
174
+
175
+ Parameters
176
+ ----------
177
+ mouseevent : `matplotlib.backend_bases.MouseEvent`
178
+
179
+ Returns
180
+ -------
181
+ contains : bool
182
+ Whether any values are within the radius.
183
+ details : dict
184
+ An artist-specific dictionary of details of the event context,
185
+ such as which points are contained in the pick radius. See the
186
+ individual Artist subclasses for details.
187
+
188
+ See Also
189
+ --------
190
+ .Artist.contains
191
+ """
167
192
for c in self .get_children ():
168
193
a , b = c .contains (mouseevent )
169
194
if a :
@@ -177,8 +202,10 @@ def set_offset(self, xy):
177
202
Parameters
178
203
----------
179
204
xy : (float, float) or callable
180
- The (x,y) coordinates of the offset in display units.
181
- A callable must have the signature::
205
+ The (x, y) coordinates of the offset in display units. These can
206
+ either be given explicitly as a tuple (x, y), or by providing a
207
+ function that converts the extent into the offset. This function
208
+ must have the signature::
182
209
183
210
def offset(width, height, xdescent, ydescent, renderer) \
184
211
-> (float, float)
@@ -188,58 +215,79 @@ def offset(width, height, xdescent, ydescent, renderer) \
188
215
189
216
def get_offset (self , width , height , xdescent , ydescent , renderer ):
190
217
"""
191
- Get the offset
218
+ Return the offset as a tuple (x, y).
219
+
220
+ The extent parameters have to be provided to handle the case where the
221
+ offset is dynamically determined by a callable (see
222
+ `~.OffsetBox.set_offset`).
223
+
224
+ Parameters
225
+ ----------
226
+ width, height, xdescent, ydescent
227
+ Extent parameters.
228
+ renderer : `.RendererBase` subclass
192
229
193
- accepts extent of the box
194
230
"""
195
231
return (self ._offset (width , height , xdescent , ydescent , renderer )
196
232
if callable (self ._offset )
197
233
else self ._offset )
198
234
199
235
def set_width (self , width ):
200
236
"""
201
- Set the width
237
+ Set the width of the box.
202
238
203
- accepts float
239
+ Parameters
240
+ ----------
241
+ width : float
204
242
"""
205
243
self .width = width
206
244
self .stale = True
207
245
208
246
def set_height (self , height ):
209
247
"""
210
- Set the height
248
+ Set the height of the box.
211
249
212
- accepts float
250
+ Parameters
251
+ ----------
252
+ height : float
213
253
"""
214
254
self .height = height
215
255
self .stale = True
216
256
217
257
def get_visible_children (self ):
218
- """
219
- Return a list of visible artists it contains.
220
- """
258
+ r"""Return a list of the visible child `.Artist`\s."""
221
259
return [c for c in self ._children if c .get_visible ()]
222
260
223
261
def get_children (self ):
224
- """
225
- Return a list of artists it contains.
226
- """
262
+ r"""Return a list of the child `.Artist`\s."""
227
263
return self ._children
228
264
229
265
def get_extent_offsets (self , renderer ):
230
- raise Exception ("" )
231
-
232
- def get_extent (self , renderer ):
233
266
"""
234
- Return with, height, xdescent, ydescent of box
267
+ Update offset of the children and return the extent of the box.
268
+
269
+ Parameters
270
+ ----------
271
+ renderer : `.RendererBase` subclass
272
+
273
+ Returns
274
+ -------
275
+ width
276
+ height
277
+ xdescent
278
+ ydescent
279
+ list of (xoffset, yoffset) pairs
235
280
"""
281
+ raise NotImplementedError (
282
+ "get_extent_offsets must be overridden in derived classes." )
283
+
284
+ def get_extent (self , renderer ):
285
+ """Return a tuple ``width, height, xdescent, ydescent`` of the box."""
236
286
w , h , xd , yd , offsets = self .get_extent_offsets (renderer )
237
287
return w , h , xd , yd
238
288
239
289
def get_window_extent (self , renderer ):
240
- '''
241
- get the bounding box in display space.
242
- '''
290
+ """Return the bounding box (`.Bbox`) in display space."""
243
291
w , h , xd , yd , offsets = self .get_extent_offsets (renderer )
244
292
px , py = self .get_offset (w , h , xd , yd , renderer )
245
293
return mtransforms .Bbox .from_bounds (px - xd , py - yd , w , h )
@@ -249,7 +297,6 @@ def draw(self, renderer):
249
297
Update the location of children if necessary and draw them
250
298
to the given *renderer*.
251
299
"""
252
-
253
300
width , height , xdescent , ydescent , offsets = self .get_extent_offsets (
254
301
renderer )
255
302
@@ -271,23 +318,29 @@ def __init__(self, pad=None, sep=None, width=None, height=None,
271
318
Parameters
272
319
----------
273
320
pad : float, optional
274
- Boundary pad .
321
+ The boundary padding in points .
275
322
276
323
sep : float, optional
277
- Spacing between items.
324
+ The spacing between items in points .
278
325
279
- width : float, optional
326
+ width, height : float, optional
327
+ Width and height of the container box in pixels, calculated if
328
+ *None*.
329
+
330
+ align : {'top', 'bottom', 'left', 'right', 'center', 'baseline'}
331
+ Alignment of boxes.
280
332
281
- height : float, optional
282
- Width and height of the container box, calculated if
283
- `None`.
333
+ mode : {'fixed', 'expand', 'equal'}
334
+ The packing mode.
284
335
285
- align : str, optional
286
- Alignment of boxes. Can be one of ``top``, ``bottom``,
287
- ``left``, ``right``, ``center`` and ``baseline``
336
+ - 'fixed' packs the given `.Artists` tight with *sep* spacing.
337
+ - 'expand' uses the maximal available space to distribute the
338
+ artists with equal spacing in between.
339
+ - 'equal': Each artist an equal fraction of the available space
340
+ and is left-aligned (or top-aligned) therein.
288
341
289
- mode : str, optional
290
- Packing mode .
342
+ children : list of `.Artist`
343
+ The artists to pack .
291
344
292
345
Notes
293
346
-----
@@ -319,23 +372,29 @@ def __init__(self, pad=None, sep=None, width=None, height=None,
319
372
Parameters
320
373
----------
321
374
pad : float, optional
322
- Boundary pad .
375
+ The boundary padding in points .
323
376
324
377
sep : float, optional
325
- Spacing between items.
378
+ The spacing between items in points .
326
379
327
- width : float, optional
380
+ width, height : float, optional
381
+ Width and height of the container box in pixels, calculated if
382
+ *None*.
328
383
329
- height : float, optional
384
+ align : {'top', 'bottom', 'left', 'right', 'center', 'baseline'}
385
+ Alignment of boxes.
330
386
331
- width and height of the container box, calculated if
332
- `None` .
387
+ mode : {'fixed', 'expand', 'equal'}
388
+ The packing mode .
333
389
334
- align : str, optional
335
- Alignment of boxes.
390
+ - 'fixed' packs the given `.Artists` tight with *sep* spacing.
391
+ - 'expand' uses the maximal available space to distribute the
392
+ artists with equal spacing in between.
393
+ - 'equal': Each artist an equal fraction of the available space
394
+ and is left-aligned (or top-aligned) therein.
336
395
337
- mode : str, optional
338
- Packing mode .
396
+ children : list of `.Artist`
397
+ The artists to pack .
339
398
340
399
Notes
341
400
-----
@@ -346,10 +405,7 @@ def __init__(self, pad=None, sep=None, width=None, height=None,
346
405
super ().__init__ (pad , sep , width , height , align , mode , children )
347
406
348
407
def get_extent_offsets (self , renderer ):
349
- """
350
- update offset of childrens and return the extents of the box
351
- """
352
-
408
+ # docstring inherited
353
409
dpicor = renderer .points_to_pixels (1. )
354
410
pad = self .pad * dpicor
355
411
sep = self .sep * dpicor
@@ -395,22 +451,29 @@ def __init__(self, pad=None, sep=None, width=None, height=None,
395
451
Parameters
396
452
----------
397
453
pad : float, optional
398
- Boundary pad .
454
+ The boundary padding in points .
399
455
400
456
sep : float, optional
401
- Spacing between items.
457
+ The spacing between items in points.
458
+
459
+ width, height : float, optional
460
+ Width and height of the container box in pixels, calculated if
461
+ *None*.
402
462
403
- width : float, optional
463
+ align : {'top', 'bottom', 'left', 'right', 'center', 'baseline'}
464
+ Alignment of boxes.
404
465
405
- height : float, optional
406
- Width and height of the container box, calculated if
407
- `None`.
466
+ mode : {'fixed', 'expand', 'equal'}
467
+ The packing mode.
408
468
409
- align : str
410
- Alignment of boxes.
469
+ - 'fixed' packs the given `.Artists` tight with *sep* spacing.
470
+ - 'expand' uses the maximal available space to distribute the
471
+ artists with equal spacing in between.
472
+ - 'equal': Each artist an equal fraction of the available space
473
+ and is left-aligned (or top-aligned) therein.
411
474
412
- mode : str
413
- Packing mode .
475
+ children : list of `.Artist`
476
+ The artists to pack .
414
477
415
478
Notes
416
479
-----
@@ -421,9 +484,7 @@ def __init__(self, pad=None, sep=None, width=None, height=None,
421
484
super ().__init__ (pad , sep , width , height , align , mode , children )
422
485
423
486
def get_extent_offsets (self , renderer ):
424
- """
425
- update offset of children and return the extents of the box
426
- """
487
+ # docstring inherited
427
488
dpicor = renderer .points_to_pixels (1. )
428
489
pad = self .pad * dpicor
429
490
sep = self .sep * dpicor
@@ -458,20 +519,30 @@ def get_extent_offsets(self, renderer):
458
519
459
520
return (width + 2 * pad , height + 2 * pad ,
460
521
xdescent + pad , ydescent + pad ,
461
- list (zip (xoffsets , yoffsets )))
522
+ list (zip (xoffsets , yoffsets )))
462
523
463
524
464
525
class PaddedBox (OffsetBox ):
526
+ """
527
+ A container to add a padding around an `.Artist`.
528
+
529
+ The `.PaddedBox` contains a `.FancyBboxPatch` that is used to visualize
530
+ it when rendering.
531
+ """
465
532
def __init__ (self , child , pad = None , draw_frame = False , patch_attrs = None ):
466
533
"""
467
- *pad* : boundary pad
468
-
469
- .. note::
470
- *pad* need to given in points and will be
471
- scale with the renderer dpi, while *width* and *height*
472
- need to be in pixels.
534
+ Parameters
535
+ ----------
536
+ child : `~matplotlib.artist.Artist`
537
+ The contained `.Artist`.
538
+ pad : float
539
+ The padding in points. This will be scaled with the renderer dpi.
540
+ In contrast *width* and *hight* are in *pixel* and thus not scaled.
541
+ draw_frame : bool
542
+ Whether to draw the contained `.FancyBboxPatch`.
543
+ patch_attrs : dict or None
544
+ Additional parameters passed to the contained `.FancyBboxPatch`.
473
545
"""
474
-
475
546
super ().__init__ ()
476
547
477
548
self .pad = pad
@@ -492,10 +563,7 @@ def __init__(self, child, pad=None, draw_frame=False, patch_attrs=None):
492
563
self ._drawFrame = draw_frame
493
564
494
565
def get_extent_offsets (self , renderer ):
495
- """
496
- update offset of childrens and return the extents of the box
497
- """
498
-
566
+ # docstring inherited.
499
567
dpicor = renderer .points_to_pixels (1. )
500
568
pad = self .pad * dpicor
501
569
@@ -510,7 +578,6 @@ def draw(self, renderer):
510
578
Update the location of children if necessary and draw them
511
579
to the given *renderer*.
512
580
"""
513
-
514
581
width , height , xdescent , ydescent , offsets = self .get_extent_offsets (
515
582
renderer )
516
583
0 commit comments