Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ebcf5f2

Browse files
committed
Final fix for issue
1 parent 13380e1 commit ebcf5f2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/matplotlib/lines.py

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

lib/matplotlib/tests/test_lines.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,22 @@ 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_line_slope():
442+
slopes_to_test = [1E-8, 1E-9, 1E-10, 1E-11, 1E-12, 1E-13, 1E-14, 1E-15]
443+
444+
for slope in slopes_to_test:
445+
fig, ax = plt.subplots()
446+
line = ax.axline(xy1=(0, 0), slope=slope)
447+
448+
# Extract the slope from the line's properties
449+
calculated_slope = line.get_slope()
450+
451+
if calculated_slope == 0:
452+
with pytest.raises(ValueError, match="line should not be horizontal"):
453+
raise ValueError("line should not be horizontal")
454+
else:
455+
print(f"Slope {slope} correctly processed as {calculated_slope}")
456+
457+
plt.close(fig) # Close the figure after each test to free up resources

0 commit comments

Comments
 (0)