Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Seaborn · Function

scatterplot

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.

How it works

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.

Syntax

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*)

Parameters

NameTypeDescription
datapandas.DataFrame, numpy.ndarray, mapping, or sequenceInput data structure; may be long-form or wide-form data reshaped internally.
x, yvectors or keys in dataVariables specifying positions on the x and y axes.
huevector or key in dataGrouping variable that produces points with different colors.
sizevector or key in dataGrouping variable that changes point size.
stylevector or key in dataGrouping variable that changes marker style.
palettestring, list, dict, or matplotlib.colors.ColormapColor-selection method for hue mapping.
hue_orderlist of stringsOrdering of hue levels.
hue_normtuple or matplotlib.colors.NormalizeNormalization for mapping hue values.
sizeslist, dict, or tupleSizes used when mapping the size semantic.
size_orderlistOrdering of size levels.
size_normtuple or matplotlib.colors.NormalizeNormalization for mapping size values.
markersboolean, list, or dictionaryWhether to use markers, or a marker specification by style level.

Returns

A matplotlib.axes.Axes object.

Key points

  • The function creates a point-based plot and supports multiple ways to distinguish groups.
  • Use the plot to compare how subsets relate across two plotted variables.
  • Map hue to a grouping variable when groups should receive different colors.
  • Pass vectors or names in data through x and y to determine point coordinates.
  • Use palette to choose the color scheme for hue levels or values.
  • The markers option enables default markers or accepts custom marker specifications for style levels.

Common mistakes

  • Using hue, size, and style together can encode three dimensions, but the resulting chart may be difficult to interpret.
  • With style=False, the function removes markers and draws lines instead, which can be surprising when a scatter appearance is expected.

Example: Scatter plot with semantic groupings

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.

When to use it

Grouped relationship analysis

Compare two numeric measurements while distinguishing categories by color.

Magnitude encoding

Represent a continuous or ordered variable through point area.

Shape-based classification

Show category membership through distinct marker shapes.

Custom figure composition

Place a scatter plot inside an existing Matplotlib axes layout.

Interview questions

QWhat does 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.

QHow do the semantic parameters work?

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.

QHow can legend placement and plotting axes be controlled?

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.relplot
  • seaborn.lineplot
  • seaborn.scatterplot

Source: seaborn.scatterplot — seaborn 0.13.2 documentation. Checked 2026-10-15.