Seaborn workaround for hue barplot

前端 未结 4 2027
时光取名叫无心
时光取名叫无心 2021-01-04 23:17

I have the following DataFrame on a Jupyter notebook which plots using seaborn a barplot:

data = {\'day_index\': [0, 1, 2, 3, 4, 5, 6],
              


        
4条回答
  •  Happy的楠姐
    2021-01-04 23:43

    I think you don't need to specify hue parameter in this case:

    In [136]: ax = sns.barplot(data=dfGroupedAgg, \
         ...:                  x='day_index', \
         ...:                  y='avg_duration', \
         ...:                  palette=sns.color_palette("Reds_d", n_colors=7, desat=1))
         ...:
    

    you can add amount of trips as annotations:

    def autolabel(rects, labels=None, height_factor=1.05):
        for i, rect in enumerate(rects):
            height = rect.get_height()
            if labels is not None:
                try:
                    label = labels[i]
                except (TypeError, KeyError):
                    label = ' '
            else:
                label = '%d' % int(height)
            ax.text(rect.get_x() + rect.get_width()/2., height_factor*height,
                    '{}'.format(label),
                    ha='center', va='bottom')
    
    autolabel(ax.patches, labels=df.trips, height_factor=1.02)
    

提交回复
热议问题