10000 Backport PR #28881: Fix `axline` for slopes <= 1E-8. Closes #28386 · matplotlib/matplotlib@00f63b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 00f63b7

Browse files
kyrachomeeseeksmachine
authored andcommitted
Backport PR #28881: Fix axline for slopes <= 1E-8. Closes #28386
1 parent 4502250 commit 00f63b7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/matplotlib/lines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ def get_transform(self):
15201520
(vxlo, vylo), (vxhi, vyhi) = ax.transScale.transform(ax.viewLim)
15211521
# General case: find intersections with view limits in either
15221522
# direction, and draw between the middle two points.
1523-
if np.isclose(slope, 0):
1523+
if slope == 0:
15241524
start = vxlo, y1
15251525
stop = vxhi, y1
15261526
elif np.isinf(slope):

lib/matplotlib/tests/test_lines.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,14 @@ def test_axline_setters():
436436
with pytest.raises(ValueError,
437437
match="Cannot set a 'slope' value while 'xy2' is set"):
438438
line2.set_slope(3)
439+
440+
441+
def test_axline_small_slope():
442+
"""Test that small slopes are not coerced to zero in the transform."""
443+
line = plt.axline((0, 0), slope=1e-14)
444+
p1 = line.get_transform().transform_point((0, 0))
445+
p2 = line.get_transform().transform_point((1, 1))
446+
# y-values must be slightly different
447+
dy = p2[1] - p1[1]
448+
assert dy > 0
449+
assert dy < 4e-12

0 commit comments

Comments
 (0)
0