'Why is the plot in matplotlib not continuous? [closed]

I'm trying to plot a dataset with solid lines in matplotlib, but it looks strange that it has not a single line instead multiple lines appear in the plot. With the dot marker there is no problem. For comparison the two plots are shown below. Can someone tell me why this is happening?

line plot dot plot



Solution 1:[1]

In general this occurs when your points are not ordered sequentially. Try sorting them first (this won't show on a scatter graph, obviously).

Solution 2:[2]

I think your y variable is coded as a factor variable. You need to change it to a continuous scale. Check pandas.to_numeric()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 2e0byo
Solution 2 user115916