Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect line of scatter plot on pandas DataFrame

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="-")

enter image description here

like image 315
Light Yagmi Avatar asked Jun 02 '16 01:06

Light Yagmi


1 Answers

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')
like image 164
Neapolitan Avatar answered Sep 22 '22 12:09

Neapolitan