Skip to content

Commit

Permalink
attempt to prevent datacursor.DataCursor._setup_annotations() (scatte…
Browse files Browse the repository at this point in the history
…r) from resetting axes limits
  • Loading branch information
twmacro committed Feb 6, 2021
1 parent 970bee1 commit fe97b5e
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions pyyeti/datacursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

def form1(x, y, n, ind, ax, line):
"""Default annotation for plots with 1 line"""
return f"x: {x:.5g}\ny: {y:5g}"
return f"x: {x:.5g}\ny: {y:.5g}"


def form2(x, y, n, ind, ax, line):
Expand Down Expand Up @@ -619,7 +619,10 @@ def _setup_annotations(self):
else:
xy = 0, 0
self._annotation[ax] = self._new_annotation(ax, xy)
xl, yl = ax.get_xlim(), ax.get_ylim()
self._dot[ax] = ax.scatter(xy[0], xy[1], **self.followdot, visible=False)
ax.set_xlim(xl)
ax.set_ylim(yl)

def _snap(self, ax, x, y):
"""Return the value in self._points closest to x, y."""
Expand All @@ -628,16 +631,8 @@ def _snap(self, ax, x, y):
for n, ln in enumerate(ax.lines):
xdata = ln.get_xdata()
ydata = ln.get_ydata()

# print("xdata\n", xdata)
# print("ydata\n", ydata)
# print("xdata - x\n", xdata - x)
# print("np.diff(ax.get_xlim())\n", np.diff(ax.get_xlim()))

dx = (xdata - x) / np.diff(ax.get_xlim())[0]
dy = (ydata - y) / np.diff(ax.get_ylim())[0]
# dx = (xdata-x)
# dy = (ydata-y)
d = np.sqrt(dx ** 2.0 + dy ** 2.0)
ind = np.argmin(d)
if d[ind] < dmin:
Expand Down

0 comments on commit fe97b5e

Please sign in to comment.