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

Skip to content

Commit 0fadaaf

Browse files
authored
Merge pull request #6799 from anntzer/annotation-default-arrow
Allow creating annotation arrows w/ default props.
2 parents 0a31b36 + 5dd8bcb commit 0fadaaf

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Annotation can use a default arrow style
2+
----------------------------------------
3+
4+
Annotations now use the default arrow style when setting `arrowprops={}`,
5+
rather than no arrow (the new behavior actually matches the documentation).

lib/matplotlib/tests/test_axes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,16 @@ def test_basic_annotate():
183183
xytext=(3, 3), textcoords='offset points')
184184

185185

186+
@cleanup
187+
def test_annotate_default_arrow():
188+
# Check that we can make an annotation arrow with only default properties.
189+
fig, ax = plt.subplots()
190+
ann = ax.annotate("foo", (0, 1), xytext=(2, 3))
191+
assert ann.arrow_patch is None
192+
ann = ax.annotate("foo", (0, 1), xytext=(2, 3), arrowprops={})
193+
assert ann.arrow_patch is not None
194+
195+
186196
@image_comparison(baseline_images=['polar_axes'])
187197
def test_polar_annotations():
188198
# you can specify the xypoint and the xytext in different

lib/matplotlib/text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,7 @@ def __init__(self, s, xy,
21512151

21522152
self.arrow = None
21532153

2154-
if arrowprops:
2154+
if arrowprops is not None:
21552155
if "arrowstyle" in arrowprops:
21562156
arrowprops = self.arrowprops.copy()
21572157
self._arrow_relpos = arrowprops.pop("relpos", (0.5, 0.5))
@@ -2220,7 +2220,7 @@ def _update_position_xytext(self, renderer, xy_pixel):
22202220
ox0, oy0 = self._get_xy_display()
22212221
ox1, oy1 = xy_pixel
22222222

2223-
if self.arrowprops:
2223+
if self.arrowprops is not None:
22242224
x0, y0 = xy_pixel
22252225
l, b, w, h = Text.get_window_extent(self, renderer).bounds
22262226
r = l + w

0 commit comments

Comments
 (0)