![](/img/trans.png)
[英]How to change scatter point size on Seaborn's relplot (seaborn.relplot not regplot)? Seaborn 0.9.0
[英]Add text to each point in a seaborn.relplot
我使用下面的代碼來生成一個relplot
:
df = pd.read_csv(r"train.csv")
df.head()
p1=sns.relplot(x="OS_Packages",y="Vulnerabilities",hue="OS_Distro",
size="High_Vulnerabilities",sizes=(400,1000), data = df)
plt.show()
我需要在 plot 中的每個點上添加文本。 我怎么能這樣做? 我已經搜索過,但只得到了regplot.
我正在尋找將文本添加到relplot
的點。
如本答案所述,您必須訪問 relplot 返回的relplot
的軸。
您的問題的簡單復制,並帶有注釋點:
import seaborn as sns
import pandas as pd
d = {'OS_Packages':[0,1,2,4], 'Vulnerabilities': [6,7,3,7],
'text':['point1','point2','point3','point4']}
df = pd.DataFrame(d)
p1 = sns.relplot(x='OS_Packages', y='Vulnerabilities',data=df )
ax = p1.axes[0,0]
for idx,row in df.iterrows():
x = row[0]
y = row[1]
text = row[2]
ax.text(x+.05,y,text, horizontalalignment='left')
這將返回以下內容:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.