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

Skip to content

Fix Annotation using different units and different coords on x/y. #15886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
import io
import warnings

Expand Down Expand Up @@ -579,6 +580,18 @@ def test_annotation_update():
rtol=1e-6)


@check_figures_equal(extensions=["png"])
def test_annotation_units(fig_test, fig_ref):
ax = fig_test.add_subplot()
ax.plot(datetime.now(), 1, "o") # Implicitly set axes extents.
ax.annotate("x", (datetime.now(), 0.5), xycoords=("data", "axes fraction"),
# This used to crash before.
xytext=(0, 0), textcoords="offset points")
ax = fig_ref.add_subplot()
ax.plot(datetime.now(), 1, "o")
ax.annotate("x", (datetime.now(), 0.5), xycoords=("data", "axes fraction"))


@image_comparison(['large_subscript_title.png'], style='mpl20')
def test_large_subscript_title():
# Remove this line when this test image is regenerated.
Expand Down
13 changes: 3 additions & 10 deletions lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -1864,19 +1864,12 @@ def is_offset(s):
return isinstance(s, str) and s.split()[0] == "offset"

if isinstance(self.xycoords, tuple):
s1, s2 = self.xycoords
if is_offset(s1) or is_offset(s2):
if any(map(is_offset, self.xycoords)):
raise ValueError("xycoords should not be an offset coordinate")
x, y = self.xy
x1, y1 = self._get_xy(renderer, x, y, s1)
x2, y2 = self._get_xy(renderer, x, y, s2)
return x1, y2
elif is_offset(self.xycoords):
raise ValueError("xycoords should not be an offset coordinate")
else:
x, y = self.xy
return self._get_xy(renderer, x, y, self.xycoords)
#raise RuntimeError("must be defined by the derived class")
x, y = self.xy
return self._get_xy(renderer, x, y, self.xycoords)

# def _get_bbox(self, renderer):
# if hasattr(bbox, "bounds"):
Expand Down