如何将参考列设置为散点图并用不同颜色绘制

How to set a reference column into a scatter plot and drawing it with different colors

我正在尝试根据 x_pos 和 y_pos 制作散点图来确定位置,但另外,我想添加一个额外的变量,该变量将是区分年份的年份不同颜色的图表。

图表的最后应该会显示很多每年不同颜色的点

我的 df 是这样的:

    Year    x_pos   y_pos
0   2015    9229    8469
1   2015    13908   5960
2   2015    8281    7889
3   2015    8522    8895
4   2015    8902    7643
...
423 2018    4170    4983
423 2018    4274    5121
423 2018    3828    5100
423 2018    1236    10532
424 2018    4188    12533

查看这个具有良好探索性数据分析 (EDA) 的 Kaggle 内核。

https://www.kaggle.com/sudalairajkumar/simple-exploration-notebook-zillow-prize/notebook

# if you are using Jupyter, then use magic function below
# %matplotlib inline

import matplotlib.pyplot as plt
import seaborn as sns

# kaggle kernel with nice exploratory data analysis (EDA)
# https://www.kaggle.com/sudalairajkumar/simple-exploration-notebook-zillow-prize/notebook
plt.figure(figsize=(8,8))
sns.scatterplot(x=df[['x_pos']].values, y=df['y_pos'].values, hue=df['year'].values)
plt.ylabel('y_label here', fontsize=12)
plt.xlabel('x_label here', fontsize=12)
plt.title('Put your title here', fontsize=15)
plt.legend(loc='upper right', ncol=1)
plt.show()