1

I am looking for a way to add a 'place holder' value on this bar graph I have. The issue is that there is no Quintile 1 for this group, but I would like to still display that with a '1' tick, left blank, then led by the remaining data. Here is what is looks like:

enter image description here

and here is my code:

df_temp = df1.loc[df1['Rep Segment_INSIDE'] == 1]
output2 = df_temp.groupby(['Quintile'])['Productivity Score', 'Funnel', 'Attainment', 
'Activity', 'Forecast Accuracy', 'Training'].mean()
output2 = output2.sort_values('Productivity Score', ascending = False)
output2 = output2.drop(columns = ['Productivity Score'], axis = 1)


output2.plot.bar(stacked = True, grid=True, rot = 0)
plt.title('Segment Inside: Average KPI Metrics', fontsize= 25)
plt.xlabel('Quintiles', fontsize = 25)
plt.ylabel('Average KPI Scores, accumulated Productivity Score (%)', fontsize = 25)
plt.xticks(fontsize = 20)
plt.yticks(np.arange(0,1.1, 0.1), fontsize = 20)
plt.legend(loc=1, prop={'size': 30})

Essentially, the bar graph should be shifted right, with ticks 1-5, 1 should be empty. Appreciate any help you can offer.

Additional side quest to this: If anyone knows how to add a paired bar to each of these quintiles, where it would be the height of the stacked bar, indicating the total score, I have also been having issues trying to figure that out.

tdy
  • 36,675
  • 19
  • 86
  • 83
ek11222
  • 59
  • 4

1 Answers1

1

To add placeholder ticks, reindex against the full range of quintiles:

output2 = output2.reindex(range(1, 6))
#            Funnel  Attainment  Activity  Accuracy  Training
# Quintiles                                                  
# 1             NaN         NaN       NaN       NaN       NaN
# 2           0.210       0.075     0.040     0.125     0.155
# 3           0.155       0.010     0.200     0.150     0.135
# 4           0.125       0.015     0.160     0.240     0.135
# 5           0.065       0.000     0.225     0.180     0.230

output2.plot.bar(stacked=True, grid=True, rot=0)

To label stack totals, annotate the row sums with a percentage f-string:

for x, y in enumerate(output2.sum(axis=1)):
    ax.annotate(f'{y:.0%}', (x, y), ha='center')

figure output

tdy
  • 36,675
  • 19
  • 86
  • 83