(self)
| 1521 | self._xy2 = xy2 |
| 1522 | |
| 1523 | def get_transform(self): |
| 1524 | ax = self.axes |
| 1525 | points_transform = self._transform - ax.transData + ax.transScale |
| 1526 | |
| 1527 | if self._xy2 is not None: |
| 1528 | # two points were given |
| 1529 | (x1, y1), (x2, y2) = \ |
| 1530 | points_transform.transform([self._xy1, self._xy2]) |
| 1531 | dx = x2 - x1 |
| 1532 | dy = y2 - y1 |
| 1533 | if dx == 0: |
| 1534 | if dy == 0: |
| 1535 | raise ValueError( |
| 1536 | f"Cannot draw a line through two identical points " |
| 1537 | f"(x={(x1, x2)}, y={(y1, y2)})") |
| 1538 | slope = np.inf |
| 1539 | else: |
| 1540 | slope = dy / dx |
| 1541 | else: |
| 1542 | # one point and a slope were given |
| 1543 | x1, y1 = points_transform.transform(self._xy1) |
| 1544 | slope = self._slope |
| 1545 | (vxlo, vylo), (vxhi, vyhi) = ax.transScale.transform(ax.viewLim) |
| 1546 | # General case: find intersections with view limits in either |
| 1547 | # direction, and draw between the middle two points. |
| 1548 | if slope == 0: |
| 1549 | start = vxlo, y1 |
| 1550 | stop = vxhi, y1 |
| 1551 | elif np.isinf(slope): |
| 1552 | start = x1, vylo |
| 1553 | stop = x1, vyhi |
| 1554 | else: |
| 1555 | _, start, stop, _ = sorted([ |
| 1556 | (vxlo, y1 + (vxlo - x1) * slope), |
| 1557 | (vxhi, y1 + (vxhi - x1) * slope), |
| 1558 | (x1 + (vylo - y1) / slope, vylo), |
| 1559 | (x1 + (vyhi - y1) / slope, vyhi), |
| 1560 | ]) |
| 1561 | return (BboxTransformTo(Bbox([start, stop])) |
| 1562 | + ax.transLimits + ax.transAxes) |
| 1563 | |
| 1564 | def draw(self, renderer): |
| 1565 | self._transformed_path = None # Force regen. |
no test coverage detected