Reputation: 1960
I have a catplot drawing using:
s = sns.catplot(x="level", y="value", hue="cond", kind=graph_type, data=df)
However, the size of the groups is not equal:
"Minimal
" has n=12 samples , and "Moderate
" has n=18 samples.
How can I add this info to the graph?
Upvotes: 3
Views: 689
Reputation: 2110
Manually calculate the sizes and add them to xticklabels, something like this
import matplotlib.pyplot as plt
import seaborn as sns
exercise = sns.load_dataset("exercise")
cnts = dict(exercise['time'].value_counts())
key = list(cnts.keys())
vals = list(cnts.values())
g = sns.catplot(x="time", y="pulse", hue="kind",order=key,
data=exercise, kind="box")
g.set_axis_labels("", "pulse")
g.set_xticklabels([(key[i]+'\n('+str(vals[i])+')') for i in range(len(key))])
plt.show()
Upvotes: 3