Grouped relationship analysis
Compare two numeric measurements while distinguishing categories by color.
Seaborn · Function
Draws a scatter plot where x/y position shows the main relationship and hue, size, and style can encode additional subsets or dimensions. It returns an axes-level Matplotlib plot.
scatterplot draws observations as points positioned by x and y. Optional hue, size, and style mappings encode additional variables through color, marker size, and marker shape, while palette, normalization, ordering, and legend options control their presentation.
seaborn.scatterplot(*data=None*, ***, *x=None*, *y=None*, *hue=None*, *size=None*, *style=None*, *palette=None*, *hue_order=None*, *hue_norm=None*, *sizes=None*, *size_order=None*, *size_norm=None*, *markers=True*, *style_order=None*, *legend='auto'*, *ax=None*, ***kwargs*)| Name | Type | Description |
|---|---|---|
data | pandas.DataFrame, numpy.ndarray, mapping, or sequence | Input data structure; may be long-form or wide-form data reshaped internally. |
x, y | vectors or keys in data | Variables specifying positions on the x and y axes. |
hue | vector or key in data | Grouping variable that produces points with different colors. |
size | vector or key in data | Grouping variable that changes point size. |
style | vector or key in data | Grouping variable that changes marker style. |
palette | string, list, dict, or matplotlib.colors.Colormap | Color-selection method for hue mapping. |
hue_order | list of strings | Ordering of hue levels. |
hue_norm | tuple or matplotlib.colors.Normalize | Normalization for mapping hue values. |
sizes | list, dict, or tuple | Sizes used when mapping the size semantic. |
size_order | list | Ordering of size levels. |
size_norm | tuple or matplotlib.colors.Normalize | Normalization for mapping size values. |
markers | boolean, list, or dictionary | Whether to use markers, or a marker specification by style level. |
A matplotlib.axes.Axes object.
hue to a grouping variable when groups should receive different colors.data through x and y to determine point coordinates.palette to choose the color scheme for hue levels or values.markers option enables default markers or accepts custom marker specifications for style levels.style=False, the function removes markers and draws lines instead, which can be surprising when a scatter appearance is expected.import seaborn as sns
import matplotlib.pyplot as plt
penguins = sns.load_dataset("penguins")
sns.scatterplot(
data=penguins,
x="bill_length_mm",
y="bill_depth_mm",
hue="species",
style="sex",
)
plt.show()This plots bill dimensions and uses color and marker shape to distinguish species and sex.
Compare two numeric measurements while distinguishing categories by color.
Represent a continuous or ordered variable through point area.
Show category membership through distinct marker shapes.
Place a scatter plot inside an existing Matplotlib axes layout.
seaborn.scatterplot do?It is an axes-level function that draws a scatter plot from x and y. The data argument can supply named columns, and the function can add semantic mappings for subsets of observations.
Follow-up: How would you encode a third variable? Use hue, size, or style; choose based on whether color, area, or marker shape best communicates the variable.
hue changes point colors, size changes point dimensions, and style changes marker appearance. These mappings let subsets of the data be distinguished independently.
Follow-up: What limitation should guide this design? Combining all three semantics can make the plot hard to interpret, so use only mappings that clarify the relationship.
legend='auto' lets Seaborn decide whether and how to show a legend for the semantic mappings. ax selects the Matplotlib axes on which to draw; otherwise, Seaborn uses the current axes context.
Follow-up: How can ordering be controlled? Supply hue_order, size_order, or style_order to specify the order of semantic levels.
seaborn.relplotseaborn.lineplotseaborn.scatterplot