FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Offsetbox default arguments by Ali-Msk · Pull Request #24652 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
18 changes: 9 additions & 9 deletions lib/matplotlib/offsetbox.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 \
Comment thread
oscargus marked this conversation as resolved.
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.

Expand Down
16 changes: 13 additions & 3 deletions lib/matplotlib/tests/test_offsetbox.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This test passes on main as well. (As the fact that pad is None is not a problem until later on.)

You need to do:

ax.add_artist(pb)
fig.draw_without_rendering()

If you can also add a similar thing for one of the packers that would be great! Can go in the same test/figure. There is a previous test for the packers that you can just copy the relevant code from, but leave the pad and sep arguments out.

ax.add_artist(pb)
fig.draw_without_rendering()

Back | FazBrowse Home | New Git URL