gpt4 book ai didi

python - 基于年龄相似度的散点图渐变色

转载 作者:行者123 更新时间:2023-12-05 06:59:40 24 4
gpt4 key购买 nike

我有来自不同社区的人,我想根据他们的距离使用不同颜色的散点图直观地绘制:如果他们靠近其他点,他们应该采用相似的颜色。

我知道对于散点图我应该使用以下内容

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

但我不知道如何设置类似的条件。例如:

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

我应该让 com1 和 com3 颜色相同,com6 颜色相似,而 com2 和 com4 应该颜色相似。

我认为这与渐变有关。你能给我一些关于如何在 python 中执行此操作的信息吗?

最佳答案

让我们将 Year 作为颜色传递:

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

输出:

enter image description here

关于python - 基于年龄相似度的散点图渐变色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64345357/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com