diff --git a/lib/matplotlib/tests/baseline_images/test_text/annotation_negative_coords.pdf b/lib/matplotlib/tests/baseline_images/test_text/annotation_negative_coords.pdf new file mode 100644 index 000000000000..e54d7738f739 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_text/annotation_negative_coords.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_text/annotation_negative_coords.png b/lib/matplotlib/tests/baseline_images/test_text/annotation_negative_coords.png new file mode 100644 index 000000000000..f5be853ae2e0 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_text/annotation_negative_coords.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_text/annotation_negative_coords.svg b/lib/matplotlib/tests/baseline_images/test_text/annotation_negative_coords.svg new file mode 100644 index 000000000000..100993c9eded --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_text/annotation_negative_coords.svg @@ -0,0 +1,694 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_text.py b/lib/matplotlib/tests/test_text.py index f82ab5142d62..eecb65621b5c 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -284,3 +284,19 @@ def test_bbox_clipping(): plt.text(0.9, 0.2, 'Is bbox clipped?', backgroundcolor='r', clip_on=True) t = plt.text(0.9, 0.5, 'Is fancy bbox clipped?', clip_on=True) t.set_bbox({"boxstyle": "round, pad=0.1"}) + + +@image_comparison(baseline_images=['annotation_negative_coords']) +def test_annotation_negative_coords(): + fig = plt.figure() + ax = plt.subplot( 1, 1, 1 ) + + ax.annotate("+fpt", (15, 40), xycoords="figure points") + ax.annotate("+fpx", (25, 30), xycoords="figure pixels") + ax.annotate("+apt", (35, 20), xycoords="axes points") + ax.annotate("+apx", (45, 10), xycoords="axes pixels") + + ax.annotate("-fpt", (-55, -40), xycoords="figure points") + ax.annotate("-fpx", (-45, -30), xycoords="figure pixels") + ax.annotate("-apt", (-35, -20), xycoords="axes points") + ax.annotate("-apx", (-25, -10), xycoords="axes pixels") diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 1b86d4597801..e1a43c64d43e 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -1531,17 +1531,17 @@ def _get_xy(self, renderer, x, y, s): if s2 == 'data': y = float(self.convert_yunits(y)) - tr = self._get_xy_transform(renderer, s) + tr = self._get_xy_transform(renderer, (x, y), s) x1, y1 = tr.transform_point((x, y)) return x1, y1 - def _get_xy_transform(self, renderer, s): + def _get_xy_transform(self, renderer, xy, s): if isinstance(s, tuple): s1, s2 = s from matplotlib.transforms import blended_transform_factory - tr1 = self._get_xy_transform(renderer, s1) - tr2 = self._get_xy_transform(renderer, s2) + tr1 = self._get_xy_transform(renderer, xy, s1) + tr2 = self._get_xy_transform(renderer, xy, s2) tr = blended_transform_factory(tr1, tr2) return tr @@ -1590,7 +1590,17 @@ def _get_xy_transform(self, renderer, s): # bbox0 = self._get_bbox(renderer, bbox) if bbox0 is not None: - xy0 = bbox0.bounds[:2] + x, y = xy + bounds = bbox0.extents + if x < 0: + x0 = bounds[2] + else: + x0 = bounds[0] + if y < 0: + y0 = bounds[3] + else: + y0 = bounds[1] + xy0 = (x0, y0) elif bbox_name == "offset": xy0 = self._get_ref_xy(renderer) @@ -1950,7 +1960,8 @@ def _update_position_xytext(self, renderer, xy_pixel): patch. """ # generate transformation, - self.set_transform(self._get_xy_transform(renderer, self.anncoords)) + self.set_transform(self._get_xy_transform( + renderer, self.xy, self.anncoords)) ox0, oy0 = self._get_xy_display() ox1, oy1 = xy_pixel pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy