0.11.2
  • Gallery
  • Tutorial
  • API
  • Site
      • Introduction
      • Release notes
      • Installing
      • Example gallery
      • Tutorial
      • API reference
      • Citing
      • Archive
  • Page
      • seaborn.rugplot

seaborn.rugplot¶

seaborn.rugplot(x=None, *, height=0.025, axis=None, ax=None, data=None, y=None, hue=None, palette=None, hue_order=None, hue_norm=None, expand_margins=True, legend=True, a=None, **kwargs)¶

Plot marginal distributions by drawing ticks along the x and y axes.

This function is intended to complement other plots by showing the location of individual observations in an unobstrusive way.

Parameters
x, yvectors or keys in data

Variables that specify positions on the x and y axes.

heightnumber

Proportion of axes extent covered by each rug element.

axis{“x”, “y”}

Axis to draw the rug on.

Deprecated since version 0.11.0: specify axis by assigning the x or y variables.

axmatplotlib.axes.Axes

Pre-existing axes for the plot. Otherwise, call matplotlib.pyplot.gca() internally.

datapandas.DataFrame, numpy.ndarray, mapping, or sequence

Input data structure. Either a long-form collection of vectors that can be assigned to named variables or a wide-form dataset that will be internally reshaped.

huevector or key in data

Semantic variable that is mapped to determine the color of plot elements.

palettestring, list, dict, or matplotlib.colors.Colormap

Method for choosing the colors to use when mapping the hue semantic. String values are passed to color_palette(). List or dict values imply categorical mapping, while a colormap object implies numeric mapping.

hue_ordervector of strings

Specify the order of processing and plotting for categorical levels of the hue semantic.

hue_normtuple or matplotlib.colors.Normalize

Either a pair of values that set the normalization range in data units or an object that will map from data units into a [0, 1] interval. Usage implies numeric mapping.

expand_marginsbool

If True, increase the axes margins by the height of the rug to avoid overlap with other elements.

legendbool

If False, do not add a legend for semantic variables.

kwargs

Other keyword arguments are passed to matplotlib.collections.LineCollection()

Returns
matplotlib.axes.Axes

The matplotlib axes containing the plot.

Examples

Add a rug along one of the axes:

import seaborn as sns; sns.set_theme()
tips = sns.load_dataset("tips")
sns.kdeplot(data=tips, x="total_bill")
sns.rugplot(data=tips, x="total_bill")
../_images/rugplot_1_0.png

Add a rug along both axes:

sns.scatterplot(data=tips, x="total_bill", y="tip")
sns.rugplot(data=tips, x="total_bill", y="tip")
../_images/rugplot_3_0.png

Represent a third variable with hue mapping:

sns.scatterplot(data=tips, x="total_bill", y="tip", hue="time")
sns.rugplot(data=tips, x="total_bill", y="tip", hue="time")
../_images/rugplot_5_0.png

Draw a taller rug:

sns.scatterplot(data=tips, x="total_bill", y="tip")
sns.rugplot(data=tips, x="total_bill", y="tip", height=.1)
../_images/rugplot_7_0.png

Put the rug outside the axes:

sns.scatterplot(data=tips, x="total_bill", y="tip")
sns.rugplot(data=tips, x="total_bill", y="tip", height=-.02, clip_on=False)
../_images/rugplot_9_0.png

Show the density of a larger dataset using thinner lines and alpha blending:

diamonds = sns.load_dataset("diamonds")
sns.scatterplot(data=diamonds, x="carat", y="price", s=5)
sns.rugplot(data=diamonds, x="carat", y="price", lw=1, alpha=.005)
../_images/rugplot_11_0.png

Back to top

© Copyright 2012-2021, Michael Waskom. Created using Sphinx 3.3.1.