Skip to content
Advertisement

seaborn: ‘rows’ and ‘x_vars’ at the same time

I want a seaborn multiplot that varies the x-axis variable by column, but varies the subset of data shown by row. I can use PairGrid to vary the variables graphed, and I can use FacetGrid to vary the subsets graphed, but I don’t see any facility to do both at once, even though it seems like a natural extension.

Is there a way to do this in seaborn currently? Or is this something that would need a feature request?

Here’s a mockup of what I’m trying to do:

label:A y:Y (plot M vs Y where label == A) (plot N vs Y where label == A)
label:B y:Y (plot M vs Y where label == B) (plot N vs Y where label == B)
x:M x:N

I’d also take the transpose of this scheme :)

an even better mockup

Advertisement

Answer

This is not a feature that directly exists in seaborn (though it is likely to become one at some point).

That said, FacetGrid and PairGrid just instantiate different mappings between a dataframe and a figure (modulo the diagonal plots in PairGrid and a few features here and there). So a plot that is naturally expressed using one tool can generally made with the other, given a data reshaping.

So you could do something like

JavaScript

enter image description here

There’s your plot, basically, but the labels are a little confusing. Let’s improve that:

JavaScript

enter image description here

A little more cumbersome, but also not so hard to wrap up into a pretty general function:

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