logzly. Python Starter Projects

Create a Beginner‑Friendly Data Visualization: Plotting Your First Chart with Matplotlib in 10 Minutes

Read this article in clean Markdown format for LLMs and AI context.

Ever opened a CSV file, stared at rows of numbers, and thought “I wish I could see this in a picture”? You’re not alone. A quick chart turns raw data into a story that anyone can read, and you don’t need a PhD in statistics to make one. In this post I’ll walk you through a 10‑minute setup that gets a simple line chart on screen, using only Python’s built‑in tools and the ever‑friendly Matplotlib library.

Why a Chart Matters Right Now

Data is everywhere – from your fitness tracker to a spreadsheet of monthly expenses. When you can turn those numbers into a visual, patterns pop out instantly. That “aha!” moment is the difference between guessing and knowing. Plus, a nice chart looks great on a report, a blog post, or even a quick Slack update.

What You’ll Need

  • Python 3.8+ – any recent version works, and it’s also the foundation for building simple automation scripts like those in our first Python automation guide.
  • Matplotlib – the core plotting library. If you don’t have it yet, run pip install matplotlib.
  • A tiny CSV file (or a list) with some numbers. I’ll use a simple list of temperatures over a week.

That’s it. No heavy dependencies, no fancy IDE. Just a text editor and a terminal.

Step 1: Set Up Your Project Folder

Create a folder called first_chart. Inside, make a file named plot.py. If you like, add a CSV called temps.csv with this content:

day,temp
Mon,68
Tue,70
Wed,72
Thu,71
Fri,69
Sat,73
Sun,75

Having a CSV lets you practice reading data, but we’ll also show how to plot directly from a Python list.

Step 2: Import the Right Modules

Open plot.py and start with these imports:

import csv
import matplotlib.pyplot as plt

csv is a standard library module that reads comma‑separated files. matplotlib.pyplot gives us a MATLAB‑style interface that feels natural for quick plots.

Step 3: Load the Data

You have two options. Pick the one that feels easier.

Option A – Read from the CSV

days = []
temps = []

with open('temps.csv', newline='') as f:
    reader = csv.DictReader(f)
    for row in reader:
        days.append(row['day'])
        temps.append(float(row['temp']))

DictReader treats the first line as column names, so you can access each field by its header. Converting the temperature to float lets us plot numeric values.

Option B – Use a Hard‑Coded List

days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
temps = [68, 70, 72, 71, 69, 73, 75]

Both give you two parallel lists: one for the x‑axis labels, one for the y‑axis values.

Step 4: Create the Plot

Now the fun part. Add the following code after the data loading block:

plt.figure(figsize=(8, 4))          # Size in inches, makes it look nice
plt.plot(days, temps, marker='o') # Line with circles at each point
plt.title('Weekly Temperature')   # Title at the top
plt.xlabel('Day of Week')          # X‑axis label
plt.ylabel('Temperature (°F)')     # Y‑axis label
plt.grid(True, linestyle='--', alpha=0.5)  # Light grid for readability
plt.tight_layout()                # Adjust spacing so labels fit
plt.show()

Let’s break that down:

  • figure sets the canvas size. A wider chart looks better on most screens.
  • plot draws the line. marker='o' adds a small circle at each data point so you can see exact values.
  • title, xlabel, ylabel are self‑explanatory.
  • grid adds faint lines that help the eye follow the data.
  • tight_layout prevents the labels from being cut off.
  • show opens a window with the chart. If you’re using a Jupyter notebook, replace show() with plt.show() as well – it works the same.

Run the script with python plot.py. A window should pop up displaying a clean line chart of the week’s temperature.

Step 5: Save the Chart (Optional)

If you need a static image for a report, add one line before show():

plt.savefig('weekly_temp.png', dpi=300)

dpi stands for dots per inch; 300 gives a print‑quality image. The file will appear in the same folder as your script.

Quick Debug Checklist

  • Import errors? Make sure Matplotlib is installed in the same environment you run the script.
  • Empty chart? Verify that days and temps contain data. Print them out before plotting if you’re unsure.
  • Labels overlapping? Increase the figure size or rotate the x‑labels with plt.xticks(rotation=45).

If you’re also looking to streamline other parts of your workflow, our guide on saving hours with simple scripts offers a quick start.

Adding a Little Flair

Matplotlib lets you customize almost everything. Here are two tiny tweaks that make a chart feel more personal:

plt.plot(days, temps, color='steelblue', linewidth=2)
plt.fill_between(days, temps, color='steelblue', alpha=0.1)

fill_between shades the area under the line, giving a subtle “area chart” look. Changing the color to something you like (maybe your brand’s hue) makes the visual instantly recognizable.

When to Move On

Your first chart is a stepping stone. Once you’re comfortable, try these next steps:

  1. Multiple series – Plot temperature and humidity on the same axes, a technique you’ll also use when creating an automation script that processes multiple data streams.
  2. Bar charts – Great for categorical data like sales per product.
  3. Interactive plots – Use plotly or mplcursors for hover‑tooltips.

But for now, celebrate the fact that you turned a list of numbers into a picture in under ten minutes. That’s the kind of quick win that keeps beginners motivated.

A Little Personal Note

I still remember the first time I plotted a chart in a coffee shop, laptop battery at 5%, Wi‑Fi sputtering. I stared at the blank window, then the line appeared and I felt like I’d just unlocked a secret level of Python. That moment reminded me why I started the Python Starter Projects blog: to give that same spark to anyone who’s ever felt stuck in a sea of data.

So go ahead, tweak the colors, add a subtitle, maybe even throw in a funny annotation like “#BestDay” on Sunday. The code is yours to shape, and the story your data wants to tell is waiting.

Reactions
Do you have any feedback or ideas on how we can improve this page?