0

So I have this basic chart:

ax1.plot(df['data1'], df['data2'], '.', label = 'data1 vs data2')

I'd like to color each point according to a third column which is a timestamp. How could I go about it ?

Catfoxes
  • 101
  • 1
  • 9
  • This question would be much easier to answer if you provided a sample dataframe. – Henry Ecker Aug 15 '21 at 21:14
  • Coming from R I thought this would be straight forward, I'm looking for something of this kind: ggplot(df, aes(d1, d2)) + geom_point(aes(colour = data3)) – Catfoxes Aug 15 '21 at 21:17
  • 1
    Seaborn is a high-level plotting library that does a lot of things like this. See the [scatterplot docs](https://seaborn.pydata.org/generated/seaborn.scatterplot.html); you can do `sns.scatterplot(data=df, x="data1", y="data2", hue="timestamp")` – a11 Aug 15 '21 at 21:47
  • 1
    or just using Pandas, `df.plot.scatter(x='data1', y='data2', c='timestamp')` – a11 Aug 15 '21 at 21:49
  • `c='timestamp'` only works with a `datetime dtype`, which is interpreted as a number, or a numeric column. It does not work with categories. `hue` from seaborn is more versatile. – Trenton McKinney Aug 15 '21 at 22:52

0 Answers0