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

Skip to content

Commit 6345ef6

Browse files
committed
Copy arrowprops argument to FancyAnnotationBbox.
... so that we don't mutate dicts passed in by the user (we in fact pop a key from arrowprops a bit later), and so that later mutations to the dict from the user side don't affect the artist.
1 parent c7a7cfd commit 6345ef6

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/matplotlib/offsetbox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ def __init__(self, offsetbox, xy,
13341334
xycoords=xycoords,
13351335
annotation_clip=annotation_clip)
13361336
self.offsetbox = offsetbox
1337-
self.arrowprops = arrowprops
1337+
self.arrowprops = arrowprops.copy() if arrowprops is not None else None
13381338
self.set_fontsize(fontsize)
13391339
self.xybox = xybox if xybox is not None else xy
13401340
self.boxcoords = boxcoords if boxcoords is not None else xycoords

lib/matplotlib/tests/test_offsetbox.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,13 @@ def test_annotationbbox_extents():
325325

326326
def test_zorder():
327327
assert OffsetBox(zorder=42).zorder == 42
328+
329+
330+
def test_arrowprops_copied():
331+
da = DrawingArea(20, 20, 0, 0, clip=True)
332+
arrowprops = {"arrowstyle": "->", "relpos": (.3, .7)}
333+
ab = AnnotationBbox(da, [.5, .5], xybox=(-0.2, 0.5), xycoords='data',
334+
boxcoords="axes fraction", box_alignment=(0., .5),
335+
arrowprops=arrowprops)
336+
assert ab.arrowprops is not ab
337+
assert arrowprops["relpos"] == (.3, .7)

0 commit comments

Comments
 (0)