diff --git a/lib/matplotlib/offsetbox.py b/lib/matplotlib/offsetbox.py index 059a6c8ae316..1d644e9dc93c 100644 --- a/lib/matplotlib/offsetbox.py +++ b/lib/matplotlib/offsetbox.py @@ -369,15 +369,15 @@ def draw(self, renderer): class PackerBase(OffsetBox): - def __init__(self, pad=None, sep=None, width=None, height=None, + def __init__(self, pad=0., sep=0., width=None, height=None, align="baseline", mode="fixed", children=None): """ Parameters ---------- - pad : float, optional + pad : float, default: 0.0 The boundary padding in points. - sep : float, optional + sep : float, default: 0.0 The spacing between items in points. width, height : float, optional @@ -502,13 +502,13 @@ class PaddedBox(OffsetBox): """ @_api.make_keyword_only("3.6", name="draw_frame") - def __init__(self, child, pad=None, draw_frame=False, patch_attrs=None): + def __init__(self, child, pad=0., draw_frame=False, patch_attrs=None): """ Parameters ---------- child : `~matplotlib.artist.Artist` The contained `.Artist`. - pad : float + pad : float, default: 0.0 The padding in points. This will be scaled with the renderer dpi. In contrast, *width* and *height* are in *pixels* and thus not scaled. @@ -1242,13 +1242,13 @@ def __init__(self, offsetbox, xy, The position *(x, y)* to place the text at. The coordinate system is determined by *boxcoords*. - xycoords : str or `.Artist` or `.Transform` or callable or \ -(float, float), default: 'data' + xycoords : single or two-tuple of str or `.Artist` or `.Transform` or \ +callable, default: 'data' The coordinate system that *xy* is given in. See the parameter *xycoords* in `.Annotation` for a detailed description. - boxcoords : str or `.Artist` or `.Transform` or callable or \ -(float, float), default: value of *xycoords* + boxcoords : single or two-tuple of str or `.Artist` or `.Transform` \ +or callable, default: value of *xycoords* The coordinate system that *xybox* is given in. See the parameter *textcoords* in `.Annotation` for a detailed description. diff --git a/lib/matplotlib/tests/test_offsetbox.py b/lib/matplotlib/tests/test_offsetbox.py index 9f6a9be1fd0c..5785cf5affe0 100644 --- a/lib/matplotlib/tests/test_offsetbox.py +++ b/lib/matplotlib/tests/test_offsetbox.py @@ -13,7 +13,7 @@ from matplotlib.offsetbox import ( AnchoredOffsetbox, AnnotationBbox, AnchoredText, DrawingArea, OffsetBox, - OffsetImage, TextArea, _get_packed_offsets, HPacker, VPacker) + OffsetImage, PaddedBox, TextArea, _get_packed_offsets, HPacker, VPacker) @image_comparison(['offsetbox_clipping'], remove_text=True) @@ -347,8 +347,9 @@ def test_packers(align): r1 = DrawingArea(x1, y1) r2 = DrawingArea(x2, y2) - hpacker = HPacker(children=[r1, r2], pad=0, sep=0, align=align) - vpacker = VPacker(children=[r1, r2], pad=0, sep=0, align=align) + hpacker = HPacker(children=[r1, r2], align=align) + vpacker = VPacker(children=[r1, r2], align=align) + renderer = fig.canvas.get_renderer() # HPacker @@ -378,3 +379,12 @@ def test_packers(align): x_height = (x2 - x1) / 2 # x-offsets, y-offsets assert_allclose([(x_height, 0), (0, -y2)], offset_pairs) + + +def test_paddedbox(): + # smoke test paddedbox for correct default value + fig, ax = plt.subplots() + at = AnchoredText("foo", 'upper left') + pb = PaddedBox(at, patch_attrs={'facecolor': 'r'}, draw_frame=True) + ax.add_artist(pb) + fig.draw_without_rendering()