I am trying to put in text into my boxplot. However after I arranged my x-axis in a specific order (superior, deluxe, family), the data labels are no longer following that order. How should I change my code to reflect that specific order?
Data:
RoomCategory ADR
514 Superior 114.75
515 Family 372.88
516 Deluxe 182.5
517 Deluxe 300.0
518 Family 371.45
519 Family 320.0
520 Deluxe 300.0
521 Family 414.0
My code:
box_plot = sns.boxplot(data=bgr21, x='RoomCategory',y='ADR',order=['Superior','Deluxe','Family'])
# printing the median value in the boxplot
medians= bgr21.groupby(['RoomCategory'])['ADR'].median()
vertical_offset = bgr21['ADR'].median() * 0.05 # offset from median for display
round_medians = np.round(medians,2)
for xtick in box_plot.get_xticks():
box_plot.text(xtick,round_medians[xtick] + vertical_offset,round_medians[xtick],
horizontalalignment='center', size='large',color='b',weight='semibold')
Output: