How to Make a Scatter Plot in Python With plt.scatter()
Visualizing data is a core part of analysis, and Python’s most popular plotting library is Matplotlib. To make a scatter plot, you reach for plt.scatter() from Matplotlib’s pyplot submodule, conventionally aliased as plt. You’ll use it to build both simple two-variable charts and richly customized plots that encode several variables at once.
By the end of this tutorial, you’ll understand that:
- A scatter plot is created by calling
plt.scatter()with two array-like sequences for the x and y values. - Marker size, color, shape, and transparency are controlled by the
s,c,marker, andalphaparameters. plt.scatter()enables per-point customization like variable size or color, whileplt.plot()with marker arguments runs faster for basic plots.- A single scatter plot can