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

Skip to content

Commit a19699f

Browse files
authored
Merge pull request #15987 from meeseeksmachine/auto-backport-of-pr-15886-on-v3.2.x
Backport PR #15886 on branch v3.2.x (Fix Annotation using different units and different coords on x/y.)
2 parents 43ec193 + da0f735 commit a19699f

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

lib/matplotlib/tests/test_text.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime
12
import io
23
import warnings
34

@@ -579,6 +580,18 @@ def test_annotation_update():
579580
rtol=1e-6)
580581

581582

583+
@check_figures_equal(extensions=["png"])
584+
def test_annotation_units(fig_test, fig_ref):
585+
ax = fig_test.add_subplot()
586+
ax.plot(datetime.now(), 1, "o") # Implicitly set axes extents.
587+
ax.annotate("x", (datetime.now(), 0.5), xycoords=("data", "axes fraction"),
588+
# This used to crash before.
589+
xytext=(0, 0), textcoords="offset points")
590+
ax = fig_ref.add_subplot()
591+
ax.plot(datetime.now(), 1, "o")
592+
ax.annotate("x", (datetime.now(), 0.5), xycoords=("data", "axes fraction"))
593+
594+
582595
@image_comparison(['large_subscript_title.png'], style='mpl20')
583596
def test_large_subscript_title():
584597
# Remove this line when this test image is regenerated.

lib/matplotlib/text.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,19 +1863,12 @@ def is_offset(s):
18631863
return isinstance(s, str) and s.split()[0] == "offset"
18641864

18651865
if isinstance(self.xycoords, tuple):
1866-
s1, s2 = self.xycoords
1867-
if is_offset(s1) or is_offset(s2):
1866+
if any(map(is_offset, self.xycoords)):
18681867
raise ValueError("xycoords should not be an offset coordinate")
1869-
x, y = self.xy
1870-
x1, y1 = self._get_xy(renderer, x, y, s1)
1871-
x2, y2 = self._get_xy(renderer, x, y, s2)
1872-
return x1, y2
18731868
elif is_offset(self.xycoords):
18741869
raise ValueError("xycoords should not be an offset coordinate")
1875-
else:
1876-
x, y = self.xy
1877-
return self._get_xy(renderer, x, y, self.xycoords)
1878-
#raise RuntimeError("must be defined by the derived class")
1870+
x, y = self.xy
1871+
return self._get_xy(renderer, x, y, self.xycoords)
18791872

18801873
# def _get_bbox(self, renderer):
18811874
# if hasattr(bbox, "bounds"):

0 commit comments

Comments
 (0)