Matplotlib & Visualisation · Lesson 137

Create a Scatter Plot

A scatter plot places one quantitative variable on each axis and draws one mark per observation, making direction, form, spread, clusters and outliers in a two-variable relationship visible.

ConceptWorked examplePracticeKnowledge check
Textbook walkthrough

Create a Scatter Plot

A scatter plot places one quantitative variable on each axis and draws one mark per observation, making direction, form, spread, clusters and outliers in a two-variable relationship visible.

Learning goal: explain why Create a Scatter Plot behaves this way, apply it to a small example, and verify the result independently. Begin by being able to justify this first step: Choose two quantitative variables measured on the same observational units.

Deeper walkthrough

Read Create a Scatter Plot as a mechanism, not a recipe

Treat this as a sequence of observable decisions rather than one opaque command. Stage 1: Choose two quantitative variables measured on the same observational units. Stage 2: Pass the x- and y-value sequences to scatter so each observation becomes one point. Stage 3: Label both axes with variable names and units; add colour/size only when they encode a defined third quantity. Final checkpoint: Check for overplotting, truncated axes and influential observations before drawing a conclusion.

Mechanism

Follow the transformation

Choose two quantitative variables measured on the same observational units.

Pass the x- and y-value sequences to scatter so each observation becomes one point.

Label both axes with variable names and units; add colour/size only when they encode a defined third quantity.

Evidence

Know what would convince you

  • Trace a tiny input by hand and compare the runtime result.
  • Inspect type, value/shape and any mutation/side effect explicitly.
Useful distinctionInput: Objects/values supplied to the operation.
Click a stage to inspect what happens, what changes, and what should be checked before moving on.
Stage 1

Choose two quantitative variables measured on…

Choose two quantitative variables measured on the same observational units. For Create a Scatter Plot, identify the exact state before this stage, the operation or rule applied here, and the observable state afterwards so the mechanism remains inspectable.

State focus: identify exactly what changed at this stage and what observable evidence confirms that change.
How it works

Trace the mechanism step by step

  1. Choose two quantitative variables measured on the same observational units.
  2. Pass the x- and y-value sequences to scatter so each observation becomes one point.
  3. Label both axes with variable names and units; add colour/size only when they encode a defined third quantity.
  4. Inspect direction, form, spread, clusters and unusual points rather than reducing the plot to a correlation claim.
  5. Check for overplotting, truncated axes and influential observations before drawing a conclusion.
Worked demonstration

Create a Scatter Plot

# Step 1 — Import the module so its functions/classes are available to the rest of this example.
import matplotlib.pyplot as plt
# Step 2 — Compute the right-hand expression and store its result in `x` for the next step.
x=[1,2,3,4]; y=[2,4,4.5,8]
# Step 3 — Encode the selected variables into a visual layer that can be inspected for pattern and anomalies.
plt.scatter(x,y)
# Step 4 — Encode the selected variables into a visual layer that can be inspected for pattern and anomalies.
plt.xlabel("x"); plt.ylabel("y")
Expected / illustrative result
The points show a generally positive association while retaining observation-level variation.
Interpret the result.

For Create a Scatter Plot, connect every important mark, axis position or summary to its source values; check how scale, ordering, aggregation or binning affects what a reader sees.

Distinctions & related ideas

Place the concept correctly

InputObjects/values supplied to the operation.
StateNames or mutable objects that may change during execution.
OutputReturned value, side effect, file, plot or exception to inspect.
Use deliberately

When it is appropriate

Use Create a Scatter Plot when it answers a defined question in Matplotlib & Visualisation and its inputs/assumptions match the current data or program state.

Boundary conditions

When to stop or reconsider

Reconsider Create a Scatter Plot when the required information is unavailable, the operation would violate a validation/data boundary, or a simpler operation answers the question more transparently.

Common mistakes

Failure modes to recognise

  • Running the operation on the wrong object/type or in the wrong environment.
  • Inferring correctness from “no exception” without checking the produced value/state.
  • Hiding a boundary case instead of making its behaviour explicit.
Verification

How to check the result

  • Trace a tiny input by hand and compare the runtime result.
  • Inspect type, value/shape and any mutation/side effect explicitly.
  • Run an edge or invalid case and confirm the exception/behaviour is deliberate.
Hands-on practice

Demonstrate understanding

Try this:

Construct a tiny example of Create a Scatter Plot. First choose two quantitative variables measured on the same observational units. Then pass the x- and y-value sequences to scatter so each observation becomes one point. Predict the result before execution and explain one boundary or failure case.

Use a handful of values and label axes/units. Point to each mark and identify the source value or aggregation that created it.
Knowledge check

Check reasoning, not memorisation

Which approach best demonstrates understanding of Create a Scatter Plot?

Quick reference

Remember the logic

Step 1Choose two quantitative variables measured on the same observational units.
Step 2Pass the x- and y-value sequences to scatter so each observation becomes one point.
Step 3Label both axes with variable names and units; add colour/size only when they encode a defined third quantity.
Step 4Inspect direction, form, spread, clusters and unusual points rather than reducing the plot to a correlation claim.
Lesson summary

What to remember

  • A scatter plot places one quantitative variable on each axis and draws one mark per observation, making direction, form, spread, clusters and outliers in a two-variable relationship visible.
  • Identify the Python objects and types involved.
  • Running the operation on the wrong object/type or in the wrong environment.
  • Trace a tiny input by hand and compare the runtime result.