seaborn.objects.Plot.pair#
- Plot.pair(x=None, y=None, wrap=None, cross=True)#
Produce subplots by pairing multiple
x
and/ory
variables.- Parameters:
- x, ysequence(s) of data vectors or identifiers
Variables that will define the grid of subplots.
- wrapint
When using only
x
ory
, “wrap” subplots across a two-dimensional grid with this many columns (when usingx
) or rows (when usingy
).- crossbool
When False, zip the
x
andy
lists such that the first subplot gets the first pair, the second gets the second pair, etc. Otherwise, create a two-dimensional grid from the cartesian product of the lists.
Examples
Plot one dependent variable against multiple independent variables by assigning
y
and pairing onx
:( so.Plot(mpg, y="acceleration") .pair(x=["displacement", "weight"]) .add(so.Dots()) )
Show multiple pairwise relationships by passing lists to both
x
andy
:( so.Plot(mpg) .pair(x=["displacement", "weight"], y=["horsepower", "acceleration"]) .add(so.Dots()) )
When providing lists for both
x
andy
, passcross=False
to pair each position in the list rather than showing all pairwise relationships:( so.Plot(mpg) .pair( x=["weight", "acceleration"], y=["displacement", "horsepower"], cross=False, ) .add(so.Dots()) )
When plotting against several
x
ory
variables, it is possible towrap
the subplots to produce a two-dimensional grid:( so.Plot(mpg, y="mpg") .pair(x=["displacement", "weight", "horsepower", "cylinders"], wrap=2) .add(so.Dots()) )
Pairing can be combined with faceting, either pairing on
y
and faceting oncol
or pairing onx
and faceting onrow
:( so.Plot(mpg, x="weight") .pair(y=["horsepower", "acceleration"]) .facet(col="origin") .add(so.Dots()) )
While typically convenient to assign pairing variables as references to the common
data
, it’s also possible to pass a list of vectors:( so.Plot(mpg["weight"]) .pair(y=[mpg["horsepower"], mpg["acceleration"]]) .add(so.Dots()) )
When customizing the plot through methods like
Plot.label()
,Plot.limit()
, orPlot.scale()
, you can refer to the individual coordinate variables asx0
,x1
, etc.:( so.Plot(mpg, y="mpg") .pair(x=["weight", "displacement"]) .label(x0="Weight (lb)", x1="Displacement (cu in)", y="MPG") .add(so.Dots()) )