4

I am trying to draw a scatter plot in Python with color code stored in 'color' column of dataframe. And I get invalid RGBA argument error.

Here's my code and data:

df.plot.scatter(x='x', y='y', c='color')  

      id         x     type     color     y
0    109       570.4       ha     r     500.8
1    110       632.4       ha     r     567.2
2    111       399.4       of     b     487.2
3    112       250.2       of     b     444.4  

...

ejshin1
  • 1,107
  • 6
  • 17
  • 35
  • 1
    I'm guessing you need to specify an RGBA hex code for the color rather than the string `'color'`. – Sumner Evans Aug 17 '17 at 15:50
  • what I want to do is reading color code from datafram 'color' column. So that I can differentiate data based on color column. – ejshin1 Aug 17 '17 at 15:54

1 Answers1

8

I just solved it by this code.

col = df['type'].map({'ha':'r', 'of':'b', 'cu':'y'})
df.plot.scatter(x='x', y='y', c=col)
ejshin1
  • 1,107
  • 6
  • 17
  • 35
  • 1
    So it seems that the argument `c` of `pd.DataFrame.plot.scatter` needs to be a list-like with the color values, rather than the name of a column containing the colors (as stated in pandas docs), right? – davalo Aug 29 '17 at 17:51