9

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

Light Yagmi
  • 5,085
  • 12
  • 43
  • 64
  • Look at this question: http://stackoverflow.com/questions/20130227/matplotlib-connect-scatterplot-points-with-line-python – Serenity Jun 02 '16 at 01:14

1 Answers1

9

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')
Neapolitan
  • 2,101
  • 9
  • 21