Gradient colour for scatter plot based on age similarity

Viewed 111

I have people from different communities that I would like to plot visually using a scatter plot with different colours based on their distance: if they are close to other points than they should take a similar colour.

I know that for a scatter plot I should use the following

ax1 = df.plot.scatter(x='Year',
                       y='Community')

but I do not know how to set a similar condition. For example:

Community            Year
com1                 2006
com2                 2012
com3                 2006
com4                 2013
com5                 1996
com6                 2008
...

I should have com1 and com3 with same colour and com6 a colour similar, while com2 and com4 should have similar colour to each other.

I think it is something about gradient. Can you give me some information on how to do it in python?

1 Answers

Let's just pass Year as color:

ax1 = df.plot.scatter(x='Year',y='Community', c=df['Year'], cmap='hot')

Output:

enter image description here

Related