scatter() (Matplotlib)
ax.scatter() plots individual (x, y) points as separate markers without connecting them. It is the chart for showing the relationship or correlation between two variables.
Matplotlib
Unlike plot, scatter draws each point on its own, which is what you want for examining how two variables relate, spotting clusters, or finding outliers. The data does not need to be ordered along x.
Its real power is the extra visual channels: the c argument colors points by a third variable (paired with a colormap and a colorbar), and the s argument sizes them by a fourth. This lets a single scatter encode four dimensions of data, which is why it is a staple of exploratory analysis.
scatter returns a PathCollection you can pass to fig.colorbar() to add a color scale. For large datasets where individual points overlap heavily, consider transparency (alpha) or a 2-D histogram instead.
Syntax
ax.scatter(x, y, s=None, c=None, cmap=None, alpha=None)Examples
Python
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
sc = ax.scatter([1, 2, 3], [4, 5, 6], c=[10, 20, 30])
print(type(sc).__name__)Output:
PathCollection