2

I am making scatter plot in seaborn and I want to add some text to each point of scatter plot according to my data ("Countries" column in hap_educ and hap_rel tables). I think I need loop to do this but cannot figure out how to do it for seaborn. Here is code I use:

https://ibb.co/hZ9NBV0

https://ibb.co/ZYLdgkt

import pandas as pd
import os
import seaborn as sns 
import matplotlib.pyplot as plt

# Set up working directory
os.chdir(r'D:/PROJECT CSS/')


#importing data from xlsx files
educ = pd.read_excel(r'D:\PROJECT CSS\educ.xlsx')
happiness= pd.read_excel(r'D:\PROJECT CSS\happiness edited.xlsx')
religious=pd.read_excel(r'D:\PROJECT CSS\religious edited.xlsx')


#Merging data into 2 tables
hap_rel = pd.merge(religious, happiness, on ='Country')
hap_educ= pd.merge(educ, happiness, on ='Country')

p1=sns.regplot(x =hap_educ['Score'], y =hap_educ['Pupil teacher ratio'], data=hap_educ, label='Countries')
plt.xlabel("Index of happiness")  
plt.ylabel("Pupil / teacher ratio") 

p2=sns.regplot(x=hap_rel['Score'], y=hap_rel['Yes'], data=hap_rel)
plt.xlabel("Index of happiness")   
plt.ylabel("Percent of religious people(1=100%)")  

Expect to see each point to be Annotated with Country name from my table

Artem Ka
  • 21
  • 1
  • 2
  • Possible duplicate of [matplotlib: how to annotate point on a scatter automatically placed arrow?](https://stackoverflow.com/questions/9074996/matplotlib-how-to-annotate-point-on-a-scatter-automatically-placed-arrow) – Diziet Asahi May 16 '19 at 09:27
  • Thank you for previous response, but how to do it for seaborn module? I have just started to learn python and i need more specific explanation. – Artem Ka May 16 '19 at 15:23

0 Answers0