I am trying to annotate each point the graphs on the loop with the country but can not figure out how to di it in a loop.
Here is the code:
import pandas as pd
import matplotlib.pyplot as plt
import csv
with open('edff.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["Name", "2000", "2001", "2002"])
writer.writerow(["Afg", "500", "529","531"])
writer.writerow(["Alb", "125", "127","129"])
writer.writerow(["Alg", "52", "54", "55"])
with open('cdff.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["Name", "2000", "2001", "2002"])
writer.writerow(["Afg", "501", "531","532"])
writer.writerow(["Alb", "124", "126","130"])
writer.writerow(["Alg", "50", "52", "55"])
edff=pd.read_csv("edff.csv")
cdff=pd.read_csv("cdff.csv")
years = edff.columns.tolist()
years.pop(0)
years = [int(ystr) for ystr in years]
n=1
for year in years:
plt.figure(figsize=(9, 6))
plt.scatter(edff[str(year)], cdff[str(year)], alpha=0.5)
#Getting the country associated with the dot
for i in range(len(edff)):
name = edff.iloc[i, 0]
plt.text(edff.iloc[i, year - 2000-n], cdff.iloc[i, year - 2000-n], name, fontsize=10)
plt.plot( [0,600],[0,600] )
n+=1
plt.xscale('log')
plt.yscale('log')
The result should look similar to this: