Skip to content
Advertisement

How to create a seaborn graph that shows probability per bin?

I would like to make a graph using seaborn. I have three types that are called 1, 2 and 3. In each type, there are groups P and F. I would like to present the graph in a way that each bin sums up to 100% and shows how many of each type are of group P and group F. I would also like to show the types as categorical rather than interpreted as numbers.

Could someone give me suggestions how to adapt the graph?

So far, I have used the following code:

JavaScript

And this is the graph:

enter image description here

Advertisement

Answer

The option multiple='fill' stretches all bars to sum up to 1 (for 100%). You can use the new ax.bar_label() to label each bar.

JavaScript

sns.displot with stacked bars to sum up to 100%

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement