I am trying to get the legend right on the figure below. It should be just 'green', 'blue' and 'red' with the corresponding color. But it is all over the place.

the code is below:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({
'category':['blue','green','red','blue','green','red','blue','green','red'],
'attempts':[8955,7881,6723,100,200,300,4567,876,54],
'success':[3000,7500,2000, 256,4567,4567,7665,543,43]
})
fig,ax = plt.subplots()
plt.scatter(df['attempts'],df['success'],c=df['category'],label=df['category'])
plt.legend(loc=2)
plt.savefig('scatter.png')
plt.show()
How do I get this right? (There is a similar one here: https://pythonspot.com/matplotlib-scatterplot/ in the second part "Scatter plot with groups", but this is not based on pandas dataframe).


