You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python/Seaborn如何在散点图的R1象限标注球员姓名

实现R1象限球员姓名标注的可行方案

完全可行,下面是基于Matplotlib的具体实现步骤,适合新手操作:

核心思路

  1. 确定四象限的分界阈值(可用数据均值、自定义数值等)
  2. 过滤出属于R1象限(通常是x、y值均高于阈值的区域)的球员数据
  3. 在散点图对应位置逐个标注球员姓名

代码示例

假设你的数据集是Pandas DataFrame格式,包含球员姓名、x轴指标(比如传球准确率)、y轴指标(比如进球数):

import matplotlib.pyplot as plt
import pandas as pd

# 加载你的数据集(替换成实际文件路径)
player_df = pd.read_csv("your_player_data.csv")

# 设定四象限分界阈值(这里用x、y指标的均值,可按需替换)
x_threshold = player_df['pass_accuracy'].mean()
y_threshold = player_df['goals'].mean()

# 绘制基础散点图
plt.scatter(player_df['pass_accuracy'], player_df['goals'])

# 绘制四象限分割线
plt.axvline(x=x_threshold, color='gray', linestyle='--')
plt.axhline(y=y_threshold, color='gray', linestyle='--')

# 筛选R1象限的球员数据
r1_players = player_df[(player_df['pass_accuracy'] > x_threshold) & (player_df['goals'] > y_threshold)]

# 为R1象限的球员标注姓名
for idx, row in r1_players.iterrows():
    # 调整fontsize、ha、va参数可避免标注重叠
    plt.text(row['pass_accuracy'], row['goals'], row['player_name'],
             fontsize=8, ha='right', va='top')

# 添加图表标签
plt.xlabel('传球准确率')
plt.ylabel('进球数')
plt.title('球员表现散点图')

plt.show()

注意事项

  • 替换代码中的pass_accuracy、goals、player_name为你数据集中的实际列名
  • 如果标注出现重叠,可缩小fontsize,或者调整ha(水平对齐)、va(垂直对齐)的取值(比如ha='left'、va='bottom')
  • 进阶优化可以使用adjustText库自动调整标注位置,安装后只需在循环标注后添加:
    from adjustText import adjust_text
    texts = [plt.text(row['pass_accuracy'], row['goals'], row['player_name']) for idx, row in r1_players.iterrows()]
    adjust_text(texts)
    

内容的提问来源于stack exchange,提问作者Bruno Queiroz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 08:35:27