I have subset of countries where I am comparing gdp per person and geographic latitude. I’ve developed code down here:
country_sub.plot(kind='scatter', figsize=(6, 4), grid=True, x=lat_col, y=gdp_ppp_col)
gdp_ppp_col = "gdp_ppp"
lat_col = "lat"
position_text = {
"Israel": (31.04605, 57_758),
"United States": (37.09024, 75_269),
"Spain": (40.463667, 29_385),
"Bulgaria": (42.733883, 13_129),
"Germany": (51.165691, 48_845),
"Ireland": (53.41291, 105_362),
"Iceland": (64.963051, 74_663)
}
for country, pos_text in position_text.items():
pos_data_x = country_sub[lat_col].loc[country]
pos_data_y = country_sub[gdp_ppp_col].loc[country]
country = "U.S." if country == "United States" else country
plt.annotate(country,
xy=(pos_data_x, pos_data_y),
xytext=pos_text,
fontsize=12,
arrowprops=dict(facecolor='black', arrowstyle='->')
)
plt.plot(pos_data_x, pos_data_y, "ro")
plt.axis([25, 70, -5000, 125000])
plt.show()
However this results in the following graph:
Is there a way to move the country annotations to the backends of the arrows?