seaborn.
scatterplot
(x=None, y=None, hue=None, style=None, size=None, data=None, palette=None, hue_order=None, hue_norm=None, sizes=None, size_order=None, size_norm=None, markers=True, style_order=None, x_bins=None, y_bins=None, units=None, estimator=None, ci=95, n_boot=1000, alpha='auto', x_jitter=None, y_jitter=None, legend='brief', ax=None, **kwargs)¶Draw a scatter plot with possibility of several semantic groupings.
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.
Parameters: | x, y : names of variables in
hue : name of variables in
size : name of variables in
style : name of variables in
data : DataFrame
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
markers : boolean, list, or dictionary, optional
style_order : list, optional
{x,y}_bins : lists or arrays or functions
units : {long_form_var}
estimator : name of pandas method or callable or None, optional
ci : int or “sd” or None, optional
n_boot : int, optional
alpha : float
{x,y}_jitter : booleans or floats
legend : “brief”, “full”, or False, optional
ax : matplotlib Axes, optional
kwargs : key, value mappings
|
---|---|
Returns: | ax : matplotlib Axes
|
See also
Examples
Draw a simple scatter plot between two variables:
>>> import seaborn as sns; sns.set()
>>> import matplotlib.pyplot as plt
>>> tips = sns.load_dataset("tips")
>>> ax = sns.scatterplot(x="total_bill", y="tip", data=tips)
Group by another variable and show the groups with different colors:
>>> ax = sns.scatterplot(x="total_bill", y="tip", hue="time",
... data=tips)
Show the grouping variable by varying both color and marker:
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... hue="time", style="time", data=tips)
Vary colors and markers to show two different grouping variables:
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... hue="day", style="time", data=tips)
Show a quantitative variable by varying the size of the points:
>>> ax = sns.scatterplot(x="total_bill", y="tip", size="size",
... data=tips)
Also show the quantitative variable by also using continuous colors:
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... hue="size", size="size",
... data=tips)
Use a different continuous color map:
>>> cmap = sns.cubehelix_palette(dark=.3, light=.8, as_cmap=True)
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... hue="size", size="size",
... palette=cmap,
... data=tips)
Change the minimum and maximum point size and show all sizes in legend:
>>> cmap = sns.cubehelix_palette(dark=.3, light=.8, as_cmap=True)
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... hue="size", size="size",
... sizes=(20, 200), palette=cmap,
... legend="full", data=tips)
Use a narrower range of color map intensities:
>>> cmap = sns.cubehelix_palette(dark=.3, light=.8, as_cmap=True)
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... hue="size", size="size",
... sizes=(20, 200), hue_norm=(0, 7),
... legend="full", data=tips)
Vary the size with a categorical variable, and use a different palette:
>>> cmap = sns.cubehelix_palette(dark=.3, light=.8, as_cmap=True)
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... hue="day", size="smoker",
... palette="Set2",
... data=tips)
Use a specific set of markers:
>>> markers = {"Lunch": "s", "Dinner": "X"}
>>> ax = sns.scatterplot(x="total_bill", y="tip", style="time",
... markers=markers,
... data=tips)
Control plot attributes using matplotlib parameters:
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... s=100, color=".2", marker="+",
... data=tips)
Pass data vectors instead of names in a data frame:
>>> iris = sns.load_dataset("iris")
>>> ax = sns.scatterplot(x=iris.sepal_length, y=iris.sepal_width,
... hue=iris.species, style=iris.species)
Pass a wide-form dataset and plot against its index:
>>> import numpy as np, pandas as pd; plt.close("all")
>>> index = pd.date_range("1 1 2000", periods=100,
... freq="m", name="date")
>>> data = np.random.randn(100, 4).cumsum(axis=0)
>>> wide_df = pd.DataFrame(data, index, ["a", "b", "c", "d"])
>>> ax = sns.scatterplot(data=wide_df)