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

Skip to content

Commit 0e1c687

Browse files
authored
Merge pull request #6892 from anntzer/keep-draggable-annotation-anncoords
FIX: Don't force anncoords to fig coords upon dragging.
2 parents 2972f15 + 37ff0e0 commit 0e1c687

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

lib/matplotlib/offsetbox.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,30 +1750,12 @@ def __init__(self, annotation, use_blit=False):
17501750

17511751
def save_offset(self):
17521752
ann = self.annotation
1753-
x, y = ann.xyann
1754-
if isinstance(ann.anncoords, tuple):
1755-
xcoord, ycoord = ann.anncoords
1756-
x1, y1 = ann._get_xy(self.canvas.renderer, x, y, xcoord)
1757-
x2, y2 = ann._get_xy(self.canvas.renderer, x, y, ycoord)
1758-
ox0, oy0 = x1, y2
1759-
else:
1760-
ox0, oy0 = ann._get_xy(self.canvas.renderer, x, y, ann.anncoords)
1761-
1762-
self.ox, self.oy = ox0, oy0
1763-
self.annotation.anncoords = "figure pixels"
1764-
self.update_offset(0, 0)
1753+
self.ox, self.oy = ann.get_transform().transform(ann.xyann)
17651754

17661755
def update_offset(self, dx, dy):
17671756
ann = self.annotation
1768-
ann.xyann = self.ox + dx, self.oy + dy
1769-
x, y = ann.xyann
1770-
1771-
def finalize_offset(self):
1772-
loc_in_canvas = self.annotation.xyann
1773-
self.annotation.anncoords = "axes fraction"
1774-
pos_axes_fraction = self.annotation.axes.transAxes.inverted()
1775-
pos_axes_fraction = pos_axes_fraction.transform_point(loc_in_canvas)
1776-
self.annotation.xyann = tuple(pos_axes_fraction)
1757+
ann.xyann = ann.get_transform().inverted().transform(
1758+
(self.ox + dx, self.oy + dy))
17771759

17781760

17791761
if __name__ == "__main__":

0 commit comments

Comments
 (0)