I need to build a bar chart from the list of tuples that I have got with key names as labels for each bar shown on the x axis, and values as heights of the bars. Here is how my input looks like:
top20 = [('Blues', 2008), ('Guadeloupe', 1894), ('Yorkshire', 1216), ('Monterrey', 1112), ('Government', 1081), ('Algeria', 972), ('Rotterdam', 920), ('Sardinia', 913), ('Mac OS', 864), ('Coffee', 858), ('Netherlands', 849), ('Oklahoma', 829), ('Tokyo', 817), ('Boating', 801), ('Finland', 765), ('Michigan', 737), ('Tamaulipas', 733), ('Croatia', 722), ('Kagoshima', 701), ('Isuzu', 678)]
Here is the code I am currently using:
plt.bar(range(len(top20)), top20.values(), align='center')
plt.xticks(range(len(top20)), list(top20.keys()))
plt.show()
I know, the logic follows a dictionary as an input, but I cannot think of a way to make this work. Please help, and thank you in advance.