I have two lists and I am plotting a graph using matplotlib. Currently, the bars are organized in the way the lists are written. I want to set them in an ascending/descending order automatically. How can I do so?
industries = ['Manufacturing', 'Food', 'Eco']
counts = [12,78,1]
plt.figure(figsize=(16,6))
bars = plt.bar(industries, counts, width=0.2, bottom=None, align='center', data=None)
plt.xlim(-0.9, len(industries) - 1 + 0.9)
for i in range(len(counts)):
percentage = ((counts[i]/(total))*100)
plt.annotate(percentage, xy=(industries[i], counts[i] + 10), ha='center')
plt.show()
Edit:
I realized that the bars are built on the basis of alphabetical order. Even if the data is sorted. How can this be fixed?