Choosing the Right Chart

Python · Data Visualization

Theory

Pick the chart from the question you want the reader to answer, not from what looks impressive. Change over time is a line plot. Comparing amounts across categories is a bar chart, sorted, and horizontal when labels are long. Part of a whole is a pie or donut only for a few slices, otherwise a stacked or 100% bar. The distribution of one numeric variable is a histogram, and comparing distributions across groups is a box plot. The relationship between two numeric variables is a scatter plot, and a grid of values such as correlations is a heatmap.

Then remove anything that does not help: 3-D effects, heavy grid lines, too many colours and unlabelled axes. Bars start at zero, axes have units and the title states the takeaway, for example 'Delhi leads sales in Q3'.

Why we use it

The same numbers can be clear or confusing depending on the chart. Matching the chart type to the question means readers see the pattern immediately instead of decoding the picture.

When to use it

Ask 'what should the reader notice?' before every chart. If two chart types fit, prefer the simpler one (usually a bar or line). Avoid pies with many slices, 3-D charts and dual y-axes, which make values hard to compare.

How it works

  1. What should the reader notice?
  2. Change over time? Yes: Line plot. No: Continue.
  3. Comparing categories? Yes: Bar chart (sorted; barh for long labels). No: Continue.
  4. Parts of a whole with 5 or fewer parts? Yes: Pie / donut, else stacked bar. No: Continue.
  5. Shape of one variable? Yes: Histogram (box plot across groups). No: Scatter for two variables, heatmap for a grid.
  6. Chart that answers the question

Syntax

# question -> chart
# trend          -> ax.plot
# compare groups -> ax.bar / ax.barh
# distribution   -> ax.hist / ax.boxplot
# relationship   -> ax.scatter
# matrix         -> ax.imshow

Example

if goal == 'trend over time':
    ax.plot(dates, values)
elif goal == 'compare categories':
    ax.barh(names, values)

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