I'd like to add lines between dots of a scatter plot drawn by pandas. I tried this, but does not work. Can I put lines on a scatter plot?
pd.DataFrame([[1,2],[10,20]]).plot(kind="scatter", x=0, y=1, style="-")
pd.DataFrame([[1,2],[10,20]]).plot.scatter(0,1,style="-")
A solution is to replot the line on top of the scatter:
df = pd.DataFrame([[1,2],[10,20]])
ax = df.plot.scatter(x=0, y=1, style='b')
df.plot.line(x=0, y=1, ax=ax, style='b')
In this case, forcing points and lines both to be blue.
If you don't need the properties of the scatter plot such as value dependent colours and sizes, just use a line plot with circles for the points:
df.plot.line(x=0, y=1, style='-o')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With