10000 Backport PR #28881 on branch v3.9.x (Fix `axline` for slopes <= 1E-8. Closes #28386) by meeseeksmachine · Pull Request #28902 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Backport PR #28881 on branch v3.9.x (Fix axline for slopes <= 1E-8. Closes #28386) #28902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ def get_transform(self):
(vxlo, vylo), (vxhi, vyhi) = ax.transScale.transform(ax.viewLim)
# General case: find intersections with view limits in either
# direction, and draw between the middle two points.
if np.isclose(slope, 0):
if slope == 0:
start = vxlo, y1
stop = vxhi, y1
elif np.isinf(slope):
Expand Down
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,14 @@ def test_axline_setters():
with pytest.raises(ValueError,
match="Cannot set a 'slope' value while 'xy2' is set"):
line2.set_slope(3)


def test_axline_small_slope():
"""Test that small slopes are not coerced to zero in the transform."""
line = plt.axline((0, 0), slope=1e-14)
p1 = line.get_transform().transform_point((0, 0))
p2 = line.get_transform().transform_point((1, 1))
# y-values must be slightly different
dy = p2[1] - p1[1]
assert dy > 0
assert dy < 4e-12
Loading
0