could someone please help me to solve my problem? I have a dataframe with x1, x2 and y. The x's represent the indexes i want to connect. The y is the high of the plot (could also be some other value). I have no idea how to connect the points with matplotlib.
import pandas as pd df = pd.DataFrame({"x1":[1,5,8,10], "x2":[3,6,9,13], "y":[1,1,1,1]})
Should look something like this.
Thank you for your help!
zip is your friend:
import matplotlib.pyplot as plt import pandas as pd df = pd.DataFrame({"x1":[1,5,8,10], "x2":[3,6,9,13], "y":[1,3,2,4]}) plt.plot(*zip((df.x1, df.y), (df.x2, df.y)), color="blue") plt.show()
1.4m articles
1.4m replys
5 comments
56.9k users