0

I want to plot a histogram of percentages using displot in seaborn (version 0.12.0), which creates a FacetGrid of subplots. Percentages should be separately calculate for each subplot. In general, one can achieve this using the parameter common_norm=False. However, when also adding a hue to the plot, the common_norm also affects the hue categories, which I do not want, because it results in bins summing up to more than 100% within one subplot:

displot with common_norm=False You can use this to reproduce the figure:

sns.displot(data=sns.load_dataset("tips"), x="tip", col="smoker", row="time", hue="sex", common_norm=False, common_bins=False, facet_kws=dict(margin_titles=True, sharey="row"), stat="percent")

My expected behaviour would be that all the bins within one subplot sum up to 100%.

Is there a way to disable the common_norm on the FacetGrid subplot level, but not on the hue-level?


@JohanC: I could not find anything on what common_norm should specifically affect, which is why I asked this question, but it does not do what you say: displot with common_norm=False

sns.displot(data=sns.load_dataset("tips"), x="tip", col="smoker", row="time", hue="sex", common_norm=True, common_bins=False, facet_kws=dict(margin_titles=True), stat="percent")

When setting common_norm=True, now the values over the whole FacetGrid sum up to 100%.

mikhub
  • 13
  • 4
  • 2
    Please provide enough code so others can better understand or reproduce the problem. – Community Oct 27 '22 at 03:02
  • Apart from missing reproducible data (e.g. one of seaborn's test data sets), your question also lacks the parameters you used to call `sns.displot`. It could also help to mention the seaborn version (preferably you use the latest one). The `common_norm` parameter is supposed to only affect one subplot at a time, taking into account the hue, not the row/col. – JohanC Oct 27 '22 at 11:19
  • @JohanC sorry, please check my edit of the question. I was not aware of the importance of my question's reproducibility or the availability of generic test data sets (it's my first seaborn/python-related question, so please indulge me). I have also responded to your claim that it only affects one subplot at a time. – mikhub Oct 27 '22 at 18:42

0 Answers0