1

I have a dataset with 'Counts' from several 'Items' per animal, for totally 291 animals. The data has been acquired at days 4, 10,21 and 60, an (edited) df.to_dense() looks like this

    Animal  Day Item Counts
0   04A     4   11   11
1   04A     4   12    6
2   04A     4   16   26
3   04A     4   20   28
4   04A     4   21   16
[...]
286 60C     60  18   43
287 60C     60  20   69
288 60C     60  21   93
289 60C     60  23   55
290 60C     60  24  114

I would like to plot the data nicely, with seaborn. For this I do sns.boxplot(data=df, x='Day', y='Counts') which gives me the plot below.

simple boxplot

Now I'd like to show the boxplots for the single animals and thought to just add the 'hue' parameter, like so: sns.boxplot(data=df, x='Day', y='Counts', hue='Animal').

boxplot with hue

The values are now nicely grouped, as I would have expected it, but they are not really aligned to the x-label. Maye I understand the hue parameter wrong, but I'd like to split the day-points into the different animals and show them (center-)aligned to the x-label.

Any tips on how to achieve this?

tk421
  • 5,775
  • 6
  • 23
  • 34
Habi
  • 1,157
  • 6
  • 18
  • I guess the plot itself is correct, right? The only issue is that it leaves the space for *all* animals for each day, while in your case it seems not all animals occur at every day, leaving a hole in the plot. This can afaik not be handled via seaborn and the hue parameter, so the idea would be to create the boxplots manually by grouping the dataframe. – ImportanceOfBeingErnest Nov 27 '17 at 12:03
  • The plot is correct, I've also seen that seaborn seems to leave some space for all animals. When I do `df.groupby(by=['Day', 'Animal'])['Counts'].describe()` I get a nice overview of the grouped data, but would now like to plot that... – Habi Nov 27 '17 at 14:19

0 Answers0