Box Plot

Python · Data Visualization

Theory

A box plot summarises a distribution with five numbers. The box runs from the first quartile (Q1, 25th percentile) to the third quartile (Q3, 75th percentile), so it holds the middle half of the data, and the line inside is the median. The box height is the interquartile range, IQR = Q3 - Q1.

The whiskers reach to the furthest data points within 1.5 x IQR of the box, and anything beyond is drawn as a separate dot: a likely outlier. For café bills [220, 250, 260, 280, 300, 310, 330, 360, 900], Q1 is 260, the median 300 and Q3 330, so the IQR is 70 and anything above 435 is flagged; the 900 bill shows as a lone dot. ax.boxplot([group_a, group_b], labels=[...]) puts several groups side by side, which makes box plots excellent for comparing distributions.

Why we use it

Box plots compare the centre, spread and outliers of several groups in one compact chart, and they flag unusual values with a clear rule rather than by eye.

When to use it

Use a box plot to compare a numeric variable across groups (salaries by department, delivery time by city) or to spot outliers. A histogram shows the full shape of one distribution better, including two peaks, which a box plot hides.

How it works

  1. Numeric values (one or more groups)
  2. Compute Q1, median and Q3
  3. IQR = Q3 - Q1; fences at Q1 - 1.5 IQR and Q3 + 1.5 IQR
  4. Is a point outside the fences? Yes: Draw it as an outlier dot. No: Whisker extends to it.
  5. Box, median line, whiskers and outliers per group

Syntax

bp = ax.boxplot([a, b, c], labels=['A', 'B', 'C'])
ax.boxplot(data, vert=False)
bp['medians'], bp['whiskers'], bp['fliers']

Example

bills = [220, 250, 260, 280, 300, 900]
fig, ax = plt.subplots()
ax.boxplot(bills)

Key points

Python topics

Getting Started

Variables & Data Types

Operators

Strings

Lists

Tuples

Sets

Dictionaries

Control Flow

Loops

Functions & OOP

Working with Data

Tooling & Errors

File Handling

Exception Handling

NumPy Library

Pandas Basics

Data Cleaning

Combining DataFrames (SQL Joins & Unions)

GroupBy & SQL-Style Analytics

Reshaping & Workflow

Data Visualization

Machine Learning (Scikit-Learn)

Advanced Python & AI

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Python for Data Analysts

From basics to business insights — the complete step-by-step Python roadmap. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Python Online 141 Python questions for data analysts — strings, records, dates, statistics and regex — with hidden tests and instant verdicts. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Python  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs real Python 3.12 in your browser (first run loads the engine)
{{ liveOutput }}
{{ liveError }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic