I have Two Categorical Columns that I have plotted with countplot in seaborn. However, the order of column is mixed up I'm not getting the highest frequency to the lowest.
for example I have this data :
| Fruit | Status |
|---|---|
| "Apple" | Available |
| Apple | Available |
| Apple | Available |
| Apple | Available |
| Orange | Unavailable |
| Orange | Available |
| Apple | Unavailable |
| Orange | Available |
| Orange | Available |
| Banana | Available |
| Banana | Unavailable |
in my plot I wish to get the bars for Apple first because they are higher than the rest
this is what I have tried :
`
total=len(temp)
sns.set(rc={'figure.figsize':(28,11.27)})
sns.set_theme(style="whitegrid")
ax = sns.countplot(x ='Fruit', hue = "Status", data = temp , order='Status')
plt.xticks(size =12)
plt.xlabel('PRTNR_NAME', size = 14)
plt.yticks(size = 12)
plt.ylabel('Status', size = 12)
plt.title("Status of fruit", size = 16)
ax.set_xticklabels(ax.get_xticklabels(), ha="right")
ax.set_xticklabels(ax.get_xticklabels(), ha="right")
for p in ax.patches:
percentage = '{:.1f}%'.format(100 * p.get_height()/total)
x = p.get_x() + p.get_width()
y = p.get_height()
ax.annotate(percentage, (x, y),ha='center')
plt.show()
`