Skip to content
Advertisement

How can I add hatching for specific bars in sns.catplot?

I use seaborn to make a categorical barplot of a df containing Pearson correlation R-values for 17 vegetation classes, 3 carbon species and 4 regions. I try to recreate a smaller sample df here:

JavaScript

This is my plotting routine:

JavaScript

(The plot looks as follows: seaborn categorical barplot)

The plot is exactly how I would like it, except that now I would like to add hatching (or any kind of distinction) for all bars where the Pearson R value is insignificant, i.e. where the p value is larger than 0.05. I found this stackoverflow entry, but my problem differs from this, as the plots that should be hatched are not in repetitive order.

Any hints will be highly appreciated!

Advertisement

Answer

To determine the height of individual bars and hatching, we get a container for each graph unit, get the height of that individual container, determine it with a specified threshold, and then set the hatching and color. Please add the following code at the end.

JavaScript

enter image description here

Edit: The data has been updated to match the actual data, and the code has been modified accordingly. Also, the logic is conditional on the value of the hatching column.

JavaScript

enter image description here

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