Reputation:
I have the following bar graph:
I would like to alphabetically order the Y-axis labels (i.e, control, exclude, necrosis, other, tissue, tumor and not control, other, necrosis, exclude, tissue, tumor). Ho do I do that?
What I tried so far?
smack = df.roi_name.value_counts()
plt.barh(width=smack.values, y=smack.index)
plt.xlim(0,50000)
plt.xlabel("ROI_NAME count")
fig = plt.gcf()
fig.set_size_inches(18.5, 10.5)
Thanks in advance!
Upvotes: 0
Views: 2384
Reputation: 1624
you just need to sort index of your dataframe when you give it to plt.barh()
, like below:
plt.barh(width=smack.values, y=smack.index.sort_values())
Upvotes: 1