Python Mathplotlib绘制平均线到散点图?

Python Mathplotlib绘制平均线到散点图?,python,pandas,matplotlib,scatter,Python,Pandas,Matplotlib,Scatter,我有一个从熊猫数据框的两列创建的散点图,我想在每个轴上添加一条线,表示平均值。用散点图可以这样做吗 plt.title("NFL Conversion Rates", fontsize=40) # simulating a pandas df['team'] column types = df.Tm x_coords = df['3D%'] y_coords = df['4D%'] binsy = [15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70,

我有一个从熊猫数据框的两列创建的散点图,我想在每个轴上添加一条线,表示平均值。用散点图可以这样做吗

plt.title("NFL Conversion Rates", fontsize=40)

# simulating a pandas df['team'] column
types = df.Tm
x_coords = df['3D%']
y_coords = df['4D%']
binsy = [15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85]
binsx = [30,35,40,45,50,55]

avg_y = y_coords.mean()
avg_y = round(avg_y, 1)
display(avg_y)

avg_x = x_coords.mean()
avg_x = round(avg_x, 1)
display(avg_x)


for i,type in enumerate(types):
    x = x_coords[i]
    y = y_coords[i]
    plt.scatter(x, y, s=30, marker='o', edgecolor='black', cmap='purple', linewidth=1, alpha = 0.5)
    plt.text(x+0.2, y+0.1, type, fontsize=14)
    plt.xlabel('3rd Down Conversion Percentage',fontsize=30)
    plt.ylabel('4th Down Conversion Percentage', fontsize=30)
    plt.xticks(binsx)
    plt.yticks(binsy)
你可以试试
plt.axvline(,color='red',ls='--')
plt.axhline(,color='red',ls='--')
。替换为所需行的值,您可以尝试
plt.axvline(,color='red',ls='--')
plt.axhline(,color='red',ls='--')
。用所需行的值替换

您可以尝试
plt.axvline(,color='red',ls='--')
plt.axhline(,color='red',ls='--')
。替换为您想要的线的值。现在,我添加该值作为答案。考虑投票和接受它作为答案。您可以尝试<代码> PLT.AXVLIN(颜色=“红色”,ls='-')和<代码> PLT.AXHLIN(颜色=红色,LS= '-')。替换为您想要的线的值。现在,我添加该值作为答案。考虑投票和接受它作为一个答案。