Skip to content

Commit da040d0

Browse files
committed
implement simpler solution for calculation of axline_transaxes
1 parent bd8e82b commit da040d0

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

lib/matplotlib/lines.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .markers import MarkerStyle
1919
from .path import Path
2020
from .transforms import (
21-
Affine2D, Bbox, BboxTransformFrom, BboxTransformTo, TransformedPath)
21+
Affine2D, Bbox, BboxTransformFrom, BboxTransformTo, TransformedPath, AffineDeltaTransform)
2222

2323
# Imported here for backward compatibility, even though they don't
2424
# really belong.
@@ -1453,23 +1453,15 @@ def __init__(self, xy1, slope, **kwargs):
14531453

14541454
def get_transform(self):
14551455
ax = self.axes
1456-
(vxlo, vylo), (vxhi, vyhi) = ax.transScale.transform(ax.viewLim)
1457-
x, y = (ax.transAxes + ax.transData.inverted()).transform(self._xy1)
1456+
x, y = self._xy1
14581457

1459-
if np.isclose(self._slope, 0):
1460-
start = vxlo, y
1461-
stop = vxhi, y
1462-
else:
1463-
# find intersections with view limits in either direction,
1464-
# and draw between the middle two points.
1465-
_, start, stop, _ = sorted([
1466-
(vxlo, y + (vxlo - x) * self._slope),
1467-
(vxhi, y + (vxhi - x) * self._slope),
1468-
(x + (vylo - y) / self._slope, vylo),
1469-
(x + (vyhi - y) / self._slope, vyhi),
1470-
])
1471-
return (BboxTransformTo(Bbox([start, stop]))
1472-
+ ax.transLimits + ax.transAxes)
1458+
dx, dy = AffineDeltaTransform(ax.transData + ax.transAxes.inverted()).transform([1, self._slope])
1459+
slope_axes = dy / dx
1460+
1461+
start = 0, slope_axes * (0 - x) + y
1462+
stop = 1, slope_axes * (1 - x) + y
1463+
1464+
return BboxTransformTo(Bbox([start, stop])) + ax.transAxes
14731465

14741466

14751467
class VertexSelector:

0 commit comments

Comments
 (0)