0

I am using the following code to create a box plot:

df.assign(index=df.groupby('stage').cumcount()).pivot('index','stage','days').plot(kind='box', sym='bD', showmeans = True)

enter image description here The code works fine, but I am wondering would it be possible to add the record number for each category (box)? Thanks!

Edamame
  • 23,718
  • 73
  • 186
  • 320
  • matplotlib's boxplot function takes a `labels` parameter. You need to compute your labels and pass them. Alternatively, compute the labels you want directly in your dataframe and use that as the grouping column" – Paul H Apr 12 '18 at 02:04
  • Look for this answer https://stackoverflow.com/a/45476485/7390366 – pcu Apr 12 '18 at 06:21
  • @pcu, I want to avoid using seaborn. Any way to do it directly? – Edamame Apr 12 '18 at 06:28
  • @PaulH, I already have xticks, so I don't want the xticks-label. Can we have the record count just on the box, not as xtick-label? Thanks! – Edamame Apr 12 '18 at 06:29
  • 1
    @Edamame my example does not use the seaborn calls to add labels. – pcu Apr 12 '18 at 06:31
  • @Edamame use `ax.text` or `ax.annonate` – Paul H Apr 12 '18 at 06:36

0 Answers0