Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5dd8bcb

Browse filesBrowse files
committed
Allow creating annotation arrows w/ default props.
`annotate(..., arrowprops={})` now uses an arrow with the default arrow properties, rather than no arrow. Note that this matches the docstring of `annotate`, which indicates that "arrowprops, if not None, is a dictionary of line properties (see matplotlib.lines.Line2D) for the arrow that connects annotation to the point." Comes down to checking for `None` instead of falsiness of `arrowprops`.
1 parent a4fdd60 commit 5dd8bcb
Copy full SHA for 5dd8bcb

File tree

Expand file treeCollapse file tree

3 files changed

+17
-2
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+17
-2
lines changed
+5Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+10Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/text.py
+2-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.