I have subset of countries where I am comparing gdp per person and geographic latitude. I’ve developed code down here:
import matplotlib.pyplot as plt
plt.rc('font', size=12)
plt.rc('axes', labelsize=14, titlesize = 14)
plt.rc('legend', fontsize =12)
plt.rc('xtick', labelsize=10)
plt.rc('ytick', labelsize=10)
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"
min_gdp_ppp = 25
max_gdp_ppp = 125_000
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', width=3,
shrink=0.08, headwidth=5))
plt.plot(pos_data_x, pos_data_y, "ro")
plt.axis([min_lat, max_lat, min_gdp_ppp, max_gdp_ppp])
plt.show()
This results in the graph below:
However there are no stems on my arrows. I’ve tried altering the arrow plot parameters with no success.
I am trying to create something that looks more like this:
From: https://www.analyticsvidhya.com/blog/2024/02/scatter-plot-visualization-in-python-using-matplotlib/