-1

I'm trying to plot a Scatter plot of Counts and Dates within a dataframe, which looks like:

                             Count
Date       Category               
08/03/2018  football       1
12/03/2018  rugby          1
13/02/2018  rugby          1
            golf           2
14/02/2018  football       1
            golf           1
19/02/2018  football       1
            fishing        1

I have made this into an index using:

df = df.reset_index()

I have converted the date into a datetime:

The graph is generated using:

label = df['Category']

plt.scatter(df['Date'], df['Count'], label=label)

How can I give a colour to each point that is of a different category, without "hardcoding"?

Samolivercz
  • 220
  • 1
  • 4
  • 11

1 Answers1

1

This was solved using the following, REF:

Date = df['Date']
Count = df['Count']
groups = df.groupby('Category')
fig, ax = plt.subplots()


for name, group in groups:
    ax.plot(group.Date, group.Count, marker='o', linestyle='', ms=10,
label=name)
ax.legend(numpoints=1)
Samolivercz
  • 220
  • 1
  • 4
  • 11