'Python: Matplotlib is connecting random points

matplotlib is connecting random points and I don't know why. The dataframe consists of a Datatimeindex, and just two number columns:

Plot

If I do this graph with the SAME data in Excel the graph is correct:

correct Plot

This is the code that I use:

plt.figure(figsize=(12,8))
plt.plot(pred_true_comp.index,pred_true_comp["predictions"], color=  "#43a2ca", label="Predictions")

plt.plot(pred_true_comp.index,pred_true_comp["true_values"], color=  "#a8ddb5", label="True Values")

plt.legend(loc = "upper right",bbox_to_anchor=(1,1))

plt.yticks(np.arange(0,1.1,0.1))
plt.axhline(y=0.5, color = "red", label = "Critical Value")
plt.title("US Predictions vs. True Values " + "(" + kernel + " " + "kernel" + "), " + Name)

#plt.savefig("US_Results/" + Model_name + "Prediction" + ".png")
plt.show()



Solution 1:[1]

I found the mistake, it was in a loop earlier. Thank you all anyway.

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 Florian R.