I'm searching to color the points of a plot using a variable containing age of people. This is the code that I use:
import matplotlib.pyplot as plt
plt.scatter(df.x.values, df.y.values, s=60, c=df['BIRTHDT'])
plt.figtext(.5,.9,'My plot', fontsize=16, ha='center',fontweight="bold")
plt.xlabel('X',fontweight="bold",fontsize=16)
plt.ylabel('Y',fontweight="bold",fontsize=16)
plt.legend()
plt.rcParams['figure.figsize'] = [16, 9]
plt.show()
I have this Warning:
No handles with labels found to put in legend
the dataset is:
ID BIRTHDT X Y
0 49.0 5 6
1 66.0 7 7
2 56.0 4 7
3 79.0 4 7
4 66.0 12 4
I want the colors based on the continuous age like: <40 = blue ; 40-60=red; >60=orange and a legend in which there is the explanation of the colors. In my own way I have no legend.
Thanks a lot