Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 58de4e2

Browse files
Ali-MskSkhaki18Krutarth-Poscargustimhoffm
authored
Fix default arguments pad and sep for OffsetBox and children
Closes #24652 Co-authored-by: Skhaki18 <[email protected]> Co-authored-by: Krutarth Patel <[email protected]> Co-authored-by: Oscar Gustafsson <[email protected]> Co-authored-by: Tim Hoffmann <[email protected]>
1 parent a836e2e commit 58de4e2

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

lib/matplotlib/offsetbox.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,15 @@ def draw(self, renderer):
375375

376376

377377
class PackerBase(OffsetBox):
378-
def __init__(self, pad=None, sep=None, width=None, height=None,
378+
def __init__(self, pad=0., sep=0., width=None, height=None,
379379
align="baseline", mode="fixed", children=None):
380380
"""
381381
Parameters
382382
----------
383-
pad : float, optional
383+
pad : float, default: 0.0
384384
The boundary padding in points.
385385
386-
sep : float, optional
386+
sep : float, default: 0.0
387387
The spacing between items in points.
388388
389389
width, height : float, optional
@@ -508,13 +508,13 @@ class PaddedBox(OffsetBox):
508508
"""
509509

510510
@_api.make_keyword_only("3.6", name="draw_frame")
511-
def __init__(self, child, pad=None, draw_frame=False, patch_attrs=None):
511+
def __init__(self, child, pad=0., draw_frame=False, patch_attrs=None):
512512
"""
513513
Parameters
514514
----------
515515
child : `~matplotlib.artist.Artist`
516516
The contained `.Artist`.
517-
pad : float
517+
pad : float, default: 0.0
518518
The padding in points. This will be scaled with the renderer dpi.
519519
In contrast, *width* and *height* are in *pixels* and thus not
520520
scaled.

lib/matplotlib/tests/test_offsetbox.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from matplotlib.offsetbox import (
1515
AnchoredOffsetbox, AnnotationBbox, AnchoredText, DrawingArea, OffsetBox,
16-
OffsetImage, TextArea, _get_packed_offsets, HPacker, VPacker)
16+
OffsetImage, PaddedBox, TextArea, _get_packed_offsets, HPacker, VPacker)
1717

1818

1919
@image_comparison(['offsetbox_clipping'], remove_text=True)
@@ -347,8 +347,9 @@ def test_packers(align):
347347
r1 = DrawingArea(x1, y1)
348348
r2 = DrawingArea(x2, y2)
349349

350-
hpacker = HPacker(children=[r1, r2], pad=0, sep=0, align=align)
351-
vpacker = VPacker(children=[r1, r2], pad=0, sep=0, align=align)
350+
hpacker = HPacker(children=[r1, r2], align=align)
351+
vpacker = VPacker(children=[r1, r2], align=align)
352+
352353
renderer = fig.canvas.get_renderer()
353354

354355
# HPacker
@@ -378,3 +379,12 @@ def test_packers(align):
378379
x_height = (x2 - x1) / 2
379380
# x-offsets, y-offsets
380381
assert_allclose([(x_height, 0), (0, -y2)], offset_pairs)
382+
383+
384+
def test_paddedbox():
385+
# smoke test paddedbox for correct default value
386+
fig, ax = plt.subplots()
387+
at = AnchoredText("foo", 'upper left')
388+
pb = PaddedBox(at, patch_attrs={'facecolor': 'r'}, draw_frame=True)
389+
ax.add_artist(pb)
390+
fig.draw_without_rendering()

0 commit comments

Comments
 (0)