doc/_docstrings/displot.ipynb
import seaborn as sns; sns.set_theme(style="ticks")
penguins = sns.load_dataset("penguins")
sns.displot(data=penguins, x="flipper_length_mm")
sns.displot(data=penguins, x="flipper_length_mm", kind="kde")
There are three main plot kinds; in addition to histograms and kernel density estimates (KDEs), you can also draw empirical cumulative distribution functions (ECDFs):
sns.displot(data=penguins, x="flipper_length_mm", kind="ecdf")
While in histogram mode, it is also possible to add a KDE curve:
sns.displot(data=penguins, x="flipper_length_mm", kde=True)
To draw a bivariate plot, assign both x and y:
sns.displot(data=penguins, x="flipper_length_mm", y="bill_length_mm")
Currently, bivariate plots are available only for histograms and KDEs:
sns.displot(data=penguins, x="flipper_length_mm", y="bill_length_mm", kind="kde")
For each kind of plot, you can also show individual observations with a marginal "rug":
g = sns.displot(data=penguins, x="flipper_length_mm", y="bill_length_mm", kind="kde", rug=True)
sns.displot(data=penguins, x="flipper_length_mm", hue="species", kind="kde")
Additional keyword arguments are passed to the appropriate underlying plotting function, allowing for further customization:
sns.displot(data=penguins, x="flipper_length_mm", hue="species", multiple="stack")
sns.displot(data=penguins, x="flipper_length_mm", hue="species", col="sex", kind="kde")
sns.displot(
data=penguins, y="flipper_length_mm", hue="sex", col="species",
kind="ecdf", height=4, aspect=.7,
)
g = sns.displot(
data=penguins, y="flipper_length_mm", hue="sex", col="species",
kind="kde", height=4, aspect=.7,
)
g.set_axis_labels("Density (a.u.)", "Flipper length (mm)")
g.set_titles("{col_name} penguins")