Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a simple scatter plot of a dataframe (preferrably with seaborn)

I'm trying to scatter plot the following dataframe:

mydf = pd.DataFrame({'x':[1,2,3,4,5,6,7,8,9], 
                 'y':[9,8,7,6,5,4,3,2,1], 
                 'z':np.random.randint(0,9, 9)},
                index=["12:00", "1:00", "2:00", "3:00", "4:00", 
                       "5:00", "6:00", "7:00", "8:00"])



        x   y   z
 12:00  1   9   1
  1:00  2   8   1
  2:00  3   7   7
  3:00  4   6   7
  4:00  5   5   4
  5:00  6   4   2
  6:00  7   3   2
  7:00  8   2   8
  8:00  9   1   8

I would like to see the times "12:00, 1:00, ..." as the x-axis and x,y,z columns on the y-axis.

When I try to plot with pandas via mydf.plot(kind="scatter"), I get the error ValueError: scatter requires and x and y column. Do I have to break down my dataframe into appropriate parameters? What I would really like to do is get this scatter plotted with seaborn.

like image 338
theQman Avatar asked Mar 26 '15 13:03

theQman


People also ask

Which command is used for drawing scatter plot in Seaborn?

scatterplot() function. We will only use the x, y parameters of the function.


1 Answers

Just running

mydf.plot(style=".")

works fine for me:

example scatterplot as result of the code above

like image 75
Carsten Avatar answered Sep 19 '22 13:09

Carsten