Skip to content

Commit 095307f

Browse files
committed
Tweak AnnotationBbox coords specification.
In AnnotationBbox, it makes sense to allow passing xycoords and boxcoords positionally, because (similarly to annotate()) something like `AnnotationBbox(box, xy1, xy2, "axes transform", "offset points")` (for example) actually reads better than `AnnotationBbox(box, xy1, xy2, xycoords="axes transform", boxcoords="offset points")` once you've seen this often enough and learn that the positional order is just (annotated_xy, box_xy, annotated_coords, box_coords). (The alternative that's fully explicit would be `AnnotationBbox(box, xy=xy1, xybox=xy2, xycoords=..., boxcoords=...)` but even that doesn't read too well because the xy kwargs names don't rhyme exactly with the coords names; or one could reorder the args to `AnnotationBbox(box, xy=xy1, xycoords=..., xybox=xy2, boxcoords=...)`, but that's really a mouthful and doesn't help API usability.) So let's just allow passing the coordinate systems positionally (undoing the change in Matplotlib 3.6 that made them kwonly). The following kwargs do remain kwonly, though. In demo_text_path: xycoords defaults to "data" so doesn't need to be specified; xybox is not specified so boxcoords is not needed.
1 parent 5f25d20 commit 095307f

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

galleries/examples/text_labels_and_annotations/demo_text_path.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,7 @@ def draw(self, renderer=None):
113113
offsetbox.add_artist(text_patch)
114114

115115
# place the anchored offset box using AnnotationBbox
116-
ab = AnnotationBbox(offsetbox, (xpos, 0.5),
117-
xycoords='data',
118-
boxcoords="offset points",
119-
box_alignment=(0.5, 0.5),
120-
)
116+
ab = AnnotationBbox(offsetbox, (xpos, 0.5), box_alignment=(0.5, 0.5))
121117

122118
ax2.add_artist(ab)
123119

lib/matplotlib/offsetbox.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,9 +1224,7 @@ def __str__(self):
12241224
return f"AnnotationBbox({self.xy[0]:g},{self.xy[1]:g})"
12251225

12261226
@_docstring.dedent_interpd
1227-
def __init__(self, offsetbox, xy, xybox=None, *,
1228-
xycoords='data',
1229-
boxcoords=None,
1227+
def __init__(self, offsetbox, xy, xybox=None, xycoords='data', boxcoords=None, *,
12301228
frameon=True, pad=0.4, # FancyBboxPatch boxstyle.
12311229
annotation_clip=None,
12321230
box_alignment=(0.5, 0.5),

lib/matplotlib/offsetbox.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ class AnnotationBbox(martist.Artist, mtext._AnnotationBase):
240240
offsetbox: OffsetBox,
241241
xy: tuple[float, float],
242242
xybox: tuple[float, float] | None = ...,
243-
*,
244243
xycoords: str
245244
| tuple[str, str]
246245
| martist.Artist
@@ -252,6 +251,7 @@ class AnnotationBbox(martist.Artist, mtext._AnnotationBase):
252251
| Transform
253252
| Callable[[RendererBase], Bbox | Transform]
254253
| None = ...,
254+
*,
255255
frameon: bool = ...,
256256
pad: float = ...,
257257
annotation_clip: bool | None = ...,

0 commit comments

Comments
 (0)