seaborn.
relplot
(x=None, y=None, hue=None, size=None, style=None, data=None, row=None, col=None, col_wrap=None, row_order=None, col_order=None, palette=None, hue_order=None, hue_norm=None, sizes=None, size_order=None, size_norm=None, markers=None, dashes=None, style_order=None, legend='brief', kind='scatter', height=5, aspect=1, facet_kws=None, **kwargs)¶Figure-level interface for drawing relational plots onto a FacetGrid.
This function provides access to several different axes-level functions
that show the relationship between two variables with semantic mappings
of subsets. The kind
parameter selects the underlying axes-level
function to use:
scatterplot()
(with kind="scatter"
; the default)lineplot()
(with kind="line"
)Extra keyword arguments are passed to the underlying function, so you should refer to the documentation for each to see kind-specific options.
The relationship between x
and y
can be shown for different subsets
of the data using the hue
, size
, and style
parameters. These
parameters control what visual semantics are used to identify the different
subsets. It is possible to show up to three dimensions independently by
using all three semantic types, but this style of plot can be hard to
interpret and is often ineffective. Using redundant semantics (i.e. both
hue
and style
for the same variable) can be helpful for making
graphics more accessible.
See the tutorial for more information.
After plotting, the FacetGrid
with the plot is returned and can
be used directly to tweak supporting plot details or add other layers.
Note that, unlike when using the underlying plotting functions directly,
data must be passed in a long-form DataFrame with variables specified by
passing strings to x
, y
, and other parameters.
Parameters: | x, y : names of variables in
hue : name in
size : name in
style : name in
data : DataFrame
row, col : names of variables in
col_wrap : int, optional
row_order, col_order : lists of strings, optional
palette : palette name, list, or dict, optional
hue_order : list, optional
hue_norm : tuple or Normalize object, optional
sizes : list, dict, or tuple, optional
size_order : list, optional
size_norm : tuple or Normalize object, optional
legend : “brief”, “full”, or False, optional
kind : string, optional
height : scalar, optional
aspect : scalar, optional
facet_kws : dict, optional
kwargs : key, value pairings
|
---|---|
Returns: | g :
|
Examples
Draw a single facet to use the FacetGrid
legend placement:
>>> import seaborn as sns
>>> sns.set(style="ticks")
>>> tips = sns.load_dataset("tips")
>>> g = sns.relplot(x="total_bill", y="tip", hue="day", data=tips)
Facet on the columns with another variable:
>>> g = sns.relplot(x="total_bill", y="tip",
... hue="day", col="time", data=tips)
Facet on the columns and rows:
>>> g = sns.relplot(x="total_bill", y="tip", hue="day",
... col="time", row="sex", data=tips)
“Wrap” many column facets into multiple rows:
>>> g = sns.relplot(x="total_bill", y="tip", hue="time",
... col="day", col_wrap=2, data=tips)
Use multiple semantic variables on each facet with specified attributes:
>>> g = sns.relplot(x="total_bill", y="tip", hue="time", size="size",
... palette=["b", "r"], sizes=(10, 100),
... col="time", data=tips)
Use a different kind of plot:
>>> fmri = sns.load_dataset("fmri")
>>> g = sns.relplot(x="timepoint", y="signal",
... hue="event", style="event", col="region",
... kind="line", data=fmri)
Change the size of each facet:
>>> g = sns.relplot(x="timepoint", y="signal",
... hue="event", style="event", col="region",
... height=5, aspect=.7, kind="line", data=fmri)