Skip to content
beginner

Create Your First Data Visualization in Python

You already know how to read a small CSV into a list or a dictionary. That skill gets you data. It does not get you understanding. Stare at twelve monthly…

Published 2026-10-02Updated 2026-10-049 min read
Hands typing on an RGB mechanical keyboard with colorful lights on a desk, creating a vibrant tech scene.
Hands typing on an RGB mechanical keyboard with colorful lights on a desk, creating a vibrant tech scene. Photo by Matheus Bertelli on Pexels.

A table of numbers hides its story. A chart tells it in one second.

You already know how to read a small CSV into a list or a dictionary. That skill gets you data. It does not get you understanding. Stare at twelve monthly values in a list and you will not instantly see whether things are climbing, flat, or quietly collapsing. Draw those same twelve values as a line, and the trend is visible before you finish blinking.

That gap between having data and seeing data is where Python data visualization starts. In this tutorial you will install one plotting library, draw your first chart, label it so it explains itself, build a chart from a real CSV file, and learn to say honestly what your chart does and does not show.

What a Chart Is Actually For

A chart is a question made visible. That is the whole job.

Before you write a single line of plotting code, name the question you are trying to answer. Almost every beginner chart answers one of three:

  • Comparison: Which category is bigger? (bar chart)
  • Trend over time: Is this going up, down, or flat? (line chart)
  • Relationship: When one value rises, does the other rise too? (scatter plot)

Pick the question first, then pick the chart. This ordering prevents most beginner mistakes, because the wrong chart type can make honest data look dishonest. A line chart drawn through unordered categories invents a trend that does not exist. A bar chart with a y-axis that starts at 90 instead of 0 makes a 2% difference look like a cliff.

The same numbers, shaped differently, tell different stories. Your job is to pick the shape that matches the question — not the shape that looks most impressive.

Knowledge check

Check your understanding

Answer this question before you continue.

Before writing plotting code, what should you do first?
Single Choice

Focus: Identify the question to answer before choosing a chart type.

Install Matplotlib and Draw Your First Line

Matplotlib is the most widely used Python plotting library, and it is the right first tool because it gives you direct control over every element of a chart. Install it from your terminal:

pip install matplotlib

Confirm it landed:

python -c "import matplotlib; print(matplotlib.__version__)"
3.8.2

Your version number will differ. What matters is that no error appears.

Now the smallest possible chart. Create a file called first_chart.py:

import matplotlib.pyplot as plt

months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
signups = [12, 19, 15, 27, 34, 41]

plt.plot(months, signups)
plt.show()

Run it:

python first_chart.py

A window opens with a line climbing from left to right. That is your first chart.

Two things to notice. First, plt.plot() takes two lists of equal length: the x-values and the y-values. Second, plt.show() opens the window and blocks until you close it. If you run this from a terminal and nothing seems to happen, check whether a window is waiting behind your editor. That surprises almost everyone the first time.

Pick the Right Chart Type for Your Question

Three side-by-side chart examples: a line connecting ordered months for a trend, bars comparing categories, and scattered points showing a relationship between two numeric values.
Start with the question: trends use lines, category comparisons use bars, and relationships between two numeric values use scatter plots.

You have three chart types that cover nearly everything a beginner needs.

Chart typeQuestion it answersData shape it expectsUse this when
Line (plt.plot)How does this change over time?Ordered x-values, numeric y-valuesMonths, days, years, sequence
Bar (plt.bar)Which category is bigger?Category names, numeric valuesProducts, teams, regions
Scatter (plt.scatter)Do these two values move together?Two numeric columns, paired rowsPrice vs. quantity, height vs. weight

Two chart types to avoid as a first attempt:

Pie charts. They are hard to read when you have more than three or four slices, and humans are bad at comparing angles. If you want to compare parts of a whole, a bar chart usually wins.

3D charts. They look impressive and communicate less. Depth adds a dimension your reader has to mentally flatten, and it often hides the values you actually care about. Save 3D for when the third dimension is the point.

A good beginner instinct: if you cannot state your question in one sentence, you do not yet know which chart to draw.

Knowledge check

Check your understanding

Answer this question before you continue.

You have two numeric columns with paired values and want to see whether they move together. Which chart type fits that question?
Single Choice

Focus: Choose a chart type suited to examining whether two numeric values move together.

Label the Chart So It Explains Itself

Right now your chart is a line with no context. Hand it to someone else and they will ask what the axes mean. Fix that with three calls:

import matplotlib.pyplot as plt

months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
signups = [12, 19, 15, 27, 34, 41]

plt.figure(figsize=(8, 5))
plt.plot(months, signups, marker="o")
plt.title("Monthly Signups, First Half of Year")
plt.xlabel("Month")
plt.ylabel("New Signups")
plt.grid(True)
plt.show()

Compare the two versions. The first was a shape. This one is a statement: signups grew from 12 to 41 over six months, with a dip in March.

Three changes did the work:

  • plt.figure(figsize=(8, 5)) sets the width and height in inches. Without it, labels get cramped on small figures.
  • plt.title(), plt.xlabel(), and plt.ylabel() give the chart a voice.
  • marker="o" puts a dot on each data point, so the reader can see exactly where the measurements are.

Add a grid or legend only when it removes ambiguity. A grid helps here because you are reading values off the y-axis. A legend is pointless with one line — there is nothing to disambiguate.

Tip: If you cannot describe your chart in one sentence using only its title and axis labels, the labels are not finished.

Build a Chart From a Real CSV File

Hardcoded lists are training wheels. Real data lives in files. You already know how to read CSV files with the csv module, so this step is mostly about one trap: CSV values arrive as strings.

Create a file called sales.csv:

month,revenue
Jan,4200
Feb,4800
Mar,4600
Apr,5300
May,6100
Jun,6800

Now read it and plot it:

import csv
import matplotlib.pyplot as plt

months = []
revenue = []

with open("sales.csv", newline="") as f:
    reader = csv.DictReader(f)
    for row in reader:
        months.append(row["month"])
        revenue.append(float(row["revenue"]))

plt.figure(figsize=(8, 5))
plt.plot(months, revenue, marker="o")
plt.title("Monthly Revenue, First Half of Year")
plt.xlabel("Month")
plt.ylabel("Revenue (USD)")
plt.grid(True)
plt.show()

Run it:

python sales_chart.py

You get a clean line chart of six months of revenue, climbing from 4,200 to 6,800.

The critical line is float(row["revenue"]). Without it, Matplotlib receives strings like "4200" and tries to plot them as categories. The result is a scrambled or flat-looking axis that has nothing to do with your data. Convert first, plot second.

Knowledge check

Check your understanding

Answer this question before you continue.

A CSV-based revenue chart treats values such as `4200` as categories instead of showing a numeric scale. What change addresses the problem described in the article?
Debugging

Focus: Convert numeric values read from a CSV from strings to numbers before plotting them as a numeric series.

revenue.append(row["revenue"])

Common Beginner Mistakes and How to Fix Them

Most "Matplotlib is broken" moments are not Matplotlib problems. They are data or setup problems wearing a plotting costume.

Plotting strings instead of numbers. If your y-axis shows category labels instead of a numeric scale, you forgot float(). Convert every numeric column before plotting.

Forgetting plt.show(). The script finishes, no window appears, and it looks like nothing happened. Add plt.show() at the end.

Mismatched list lengths. plt.plot(x, y) requires both lists to be the same length. If you get a ValueError, print len(months) and len(revenue) before plotting. One of them is wrong.

A chart that looks wrong is usually a data problem. Before you blame the library, print the first five values of each list. If the numbers are wrong, the chart will be wrong — and no amount of styling will fix it.

Common mistake: Assuming the chart is lying when the data is. Inspect the values first. The library draws exactly what you give it.

Read Your Chart Honestly

A chart is an argument, and arguments can mislead — sometimes by accident.

Your line chart shows six months of revenue going up. It does not show:

  • What happened before January. Maybe revenue was higher last year and this is a recovery, not growth.
  • What happened after June. The line stops because the data stops, not because the trend does.
  • Why the numbers moved. A price change, a new customer, and a seasonal shift all produce the same line.

Axis scaling is the quietest lie. If your y-axis starts at 4,000 instead of 0, a 60% rise looks like a vertical wall. If it starts at 0, the same rise looks like a gentle slope. Neither is wrong — but you should know which one you drew.

And in a scatter plot, two values moving together is correlation, not cause. Ice cream sales and drowning deaths rise together in summer. Ice cream does not cause drowning. A third factor — warm weather — drives both.

Note: Write two sentences after every chart. One describes what it shows. One describes what it cannot tell you. That habit will make you a better analyst than most people who have been plotting for years.

Knowledge check

Check your understanding

Answer this question before you continue.

A scatter plot shows two values rising together. What conclusion is justified by that pattern alone?
Misconception Check

Focus: Distinguish a relationship shown by a scatter plot from evidence that one variable causes another.

Practice: Chart Your Own Data

Time to run this on your own numbers.

Task: Take a small CSV you already have, or make one with five to ten rows. Plot it.

Requirements:

  1. Choose the chart type based on your question, not on what looks nice.
  2. Add a title and both axis labels.
  3. Write the two-sentence interpretation: what it shows, what it cannot tell you.

Stretch goal: Change figsize and turn the grid on. Then decide — did the chart get clearer, or just busier? There is no single right answer, but you should be able to defend your choice.

Once you can read a file, clean the values, and chart the result, you have the three pieces of a small reporting script. That is the next step: combining file reading, sorting or filtering, and charting into one script that runs on demand and produces a picture you can send to someone else.

Name the question. Pick the chart. Label it. Then say what it shows — and what it does not.

Knowledge check

Final check

Finish the article by checking the ideas you just learned.

In the article's script, what happens when Python reaches `plt.show()`?
Question 1 of 2Single Choice

Focus: Describe what `plt.show()` does in the beginner script shown in the article.

A call to `plt.plot(months, revenue)` raises a `ValueError`. The lists contain different numbers of values. What should you check or fix first?
Question 2 of 2Debugging

Focus: Recognize that the x- and y-value lists passed to `plt.plot()` must have the same length.

months = ["Jan", "Feb", "Mar"]
revenue = [4200, 4800]
plt.plot(months, revenue)

References

  1. Python Data Visualization – Real Pythonrealpython.com
Practical resource

Want a more structured Python path?

Use the Python Starter Pack to turn scattered tutorials into a focused practice path.

View the bundle
Coming soon

Python for Artificial Intelligence Starter Pack

Build a Python foundation you can actually use. The Python for AI Starter Pack brings together a guided path through setup, core programming concepts, data structures, files, JSON, APIs, debugging, and practical projects—so you can move quickly from running your first program to understanding and building useful software.

$9
PDF BundlePythonAIBeginner
  • 264-page illustrated PDF
  • 12 guided Python chapters
  • Visual concept diagrams
  • Self-assessment quizzes
  • Bonus deep-dive sections
  • Files, JSON, APIs, debugging & projects
  • Foundation for data, automation & AI

Coming soon

Free Python bundle

Get the LearnPyFast Python for Artificial Intelligence Starter Bundle

Build a Python foundation you can actually use. The Python for Artificial Intelligence Starter Pack brings together a guided path through setup, core programming concepts, data structures, files, JSON, APIs, debugging, and practical projects—so you can move quickly from running your first program to understanding and building useful software.

You’ll receive the bundle by email. You can unsubscribe anytime.

No spam. You can unsubscribe anytime. See our Privacy policy.

Related sites

Continue beyond Python

Explore related Worldmonger sites when you want to move from Python basics into JavaScript or LLM application building.

JavaScript tutorialstutorial

LearnJSFast

Beginner-friendly JavaScript tutorials for practical web development and self-taught developers.

JavaScriptFrontendWeb development
Visit LearnJSFast
LLM tutorialstutorial

LearnLLMFast

Practical LLM tutorials for builders who want to understand prompting, workflows, agents, and AI applications.

LLMAIBuilders
Visit LearnLLMFast

Keep learning

Related tutorials

Continue with nearby Python topics and beginner-friendly explanations.

Vibrant autumn landscape featuring a solitary oak tree in a green field under a cloudy sky.
beginner
10 min read

Basic File I/O in Python

A Python program that never touches a file forgets everything the moment it exits. File I/O is how your code keeps data after the run ends—saving notes,…

Read tutorial