I was trying to follow an example outlined here https://stackoverflow.com/a/61973946
The code, after small adjustments looks like this:
def pos_image(x, y, pays, haut):
pays = countries.get(pays).alpha2.lower()
fichier = "iso-flag-png"
fichier += f"/{pays}.png"
im = mpimg.imread(fichier)
ratio = 4 / 3
w = ratio * haut
print(w)
ax.imshow(im,
extent=(x - w, x, y, y + haut),
zorder=2)
plt.style.use('seaborn')
fig, ax = plt.subplots()
liste_pays = [('France', 10), ('USA', 9), ('Spain', 5), ('Italy', 5)]
X = [p[1] for p in liste_pays]
Y = [p[0] for p in liste_pays]
haut = .8
r = ax.barh(y=Y, width=X, height=haut, zorder=1)
y_bar = [rectangle.get_y() for rectangle in r]
for pays, y in zip(liste_pays, y_bar):
pos_image(pays[1], y, pays[0], haut)
plt.show()
However, the resulting plot looks like this
Showing only the last value of the list. What am i doing wrong?
Thank you
plt.xlim
andplt.ylim
need to be set explicitly (also becauseimshow
messes with them.)"? – Paranoiac