0

I have the following bar graph:

Click here for 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!

1 Answers1

1

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())
ashkangh
  • 1,594
  • 1
  • 6
  • 9
  • you can aslo rearrange index of your dataframe before plotting, and then plot it, like below: `df = df.sort_index()` `plt.barh(width=smack.values, y=smack.index.)` – ashkangh Feb 02 '21 at 15:07