首页 > 解决方案 > Python数据标签问题

问题描述

我想创建一个多个子图,我需要在散点旁边绘制一个带有学生姓名的散点图。但不知何故,我明白了。我不知道我应该做什么改变。请检查我的输出和代码。

#creating the subplots
fig, axes = plt.subplots(1, 4, figsize=(12,3))
df = pd.DataFrame(data,  columns =['Averagemarks', 'Name'])
x = df["Name"]
y = df["Averagemarks"]
rslt_df  = df.loc[(df['Averagemarks'] > 0) & (df['Averagemarks'] <= 60), 'Name']
rslt_df1 = df.loc[(df['Averagemarks'] > 61) & (df['Averagemarks'] <= 70), 'Name']
rslt_df2 = df.loc[(df['Averagemarks'] > 71) & (df['Averagemarks'] <= 80), 'Name']
rslt_df3 = df.loc[(df['Averagemarks'] > 81) & (df['Averagemarks'] <= 100), 'Name']


#Subplot D
ax1 = plt.subplot(2, 2, 1, frameon=True) 
plt.title("Student's in the range 'D'")
subplt = sns.scatterplot(rslt_df, y, color = 'red')
plt.yticks(np.arange(0, 61, 5)) 
plt.xticks(rotation = 90, size = 8)
subplt.s[enter image description here][1]et_facecolor('#E5E7E9')

'''for p in zip(subplt.get_xticks(), x): subplt.text(p[0], p 1 +8.5, p 1 , color='k',fontsize = 13)'''

for i,j in enumerate(rslt_df.astype(str)):
        subplt.text(i+0.1,i,j,fontsize = 6,color="b")

plt.show()

标签: pythonscatter-plot

解决方案


推荐阅读