Scatter Plots

Matplotlib is a Python library for creating charts and visualizations — and the scatter plot is how you reveal the relationship between two numeric variables, one dot per observation.

Learn Scatter Plots in our free Matplotlib course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick reference.

Part of the free Matplotlib course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

In this lesson you'll plot x against y, resize and recolor points, encode a third variable with color, and add a colorbar legend.

A scatter plot places one dot per observation at its (x, y) position. Pass two lists of equal length to plt.scatter() and look for patterns — a rising cloud means the two variables move together.

What you'll see: eight orange dots climbing steadily from lower-left to upper-right. The clear upward trend shows that more study hours line up with higher exam scores — a positive correlation.

The s argument controls dot size and marker controls the shape. Lowering alpha makes overlapping points reveal denser regions. Together these turn a plain scatter into a richer picture.

What you'll see: 200 teal triangles scattered randomly across a unit square. Because alpha is 0.5, spots where triangles overlap look darker, hinting at where points cluster.

A scatter plot can show a third dimension: pass an array to c and a colormap with cmap , then call plt.colorbar() to add a legend mapping colors back to values.

What you'll see: 150 dots scattered across the square, each shaded from dark purple (low) through green to bright yellow (high) according to its temperature. A vertical colorbar on the right labels exactly which color maps to which value.

Replace each ___ to plot points and label both axes.

Your x and y lists have different lengths. Every point needs both an x and a y value.

You called plt.colorbar() without a c array. The colorbar maps the values you pass to c .

Build a bubble chart where dot size encodes a third value, colored by a colormap.

Lesson 9 complete — you can reveal relationships in data!

You plotted x against y, customized dot size, shape and transparency, and encoded a third variable with color plus a colorbar.

🚀 Up next: Pie Charts — show how a whole splits into parts as percentage slices.

Practice quiz

Which function draws one dot per observation?

  • plt.scatter()
  • plt.dots()
  • plt.points()
  • plt.cloud()

Answer: plt.scatter(). plt.scatter(x, y) places a dot at each (x, y) position.

Which argument controls the size of the dots?

  • size=
  • r=
  • s=
  • d=

Answer: s=. The s= argument sets dot size; an array sizes each dot individually.

Which argument colors each point by a value?

  • color=
  • c=
  • tint=
  • shade=

Answer: c=. Pass an array to c= so each dot is colored by its value.

Which argument selects the colormap?

  • palette=
  • colormap=
  • cmap=
  • scale=

Answer: cmap=. cmap= picks the colormap, e.g. cmap='viridis'.

What does alpha=0.5 do on a dense scatter plot?

  • Doubles the dot size
  • Makes overlaps reveal denser regions
  • Hides every dot
  • Changes the colormap

Answer: Makes overlaps reveal denser regions. alpha sets transparency so overlapping dots appear darker, revealing clusters.

Which call adds a legend mapping colors to values?

  • plt.legend()
  • plt.colorscale()
  • plt.cbar()
  • plt.colorbar()

Answer: plt.colorbar(). plt.colorbar() adds a bar showing how colors map to values.

Which marker= value draws triangles?

  • 'o'
  • 's'
  • '*'
  • '^'

Answer: '^'. marker='^' draws upward triangles; 'o' is a circle, 's' a square.

When is a scatter plot preferred over a line plot?

  • When points are independent observations
  • When data changes over time
  • When you need a running total
  • When showing percentages

Answer: When points are independent observations. Scatter plots reveal correlation between two variables for independent observations.

What error appears when x and y lengths differ?

  • KeyError
  • TypeError
  • ValueError: x and y must be the same size
  • IndexError

Answer: ValueError: x and y must be the same size. Every point needs both an x and a y, so unequal lengths raise a ValueError.

How do you encode a third variable as dot size (bubble chart)?

  • Pass an array to s=
  • Pass an array to alpha=
  • Pass an array to marker=
  • Pass an array to label=

Answer: Pass an array to s=. Passing an array to s= sizes each dot individually, making a bubble chart.