0Pricing
Data Science Academy · Lesson

Line and Bar Charts in matplotlib

Plotting straight from a DataFrame.

Line and Bar Charts in matplotlib is a free Data Science Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Data Science Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Pictures Beat Tables

A wall of numbers hides trends. A quick chart reveals them instantly, which is why every analysis ends with a plot. 📊

Import pyplot Once

The drawing engine lives in matplotlib.pyplot, almost always imported as plt. That short alias keeps every plot call tidy.

import matplotlib.pyplot as plt

Line Charts Show Change

Reach for a line chart when something moves over a continuous axis, like sales rising month after month.

plt.plot(months, sales)

Bars Compare Categories

Use a bar chart to compare separate groups side by side, like total sales for each region.

plt.bar(regions, totals)

Plot Straight From pandas

Every Series and DataFrame has a built-in .plot that calls matplotlib for you, so you skip the manual setup.

df["sales"].plot()

Choose the Kind

The pandas plot takes a kind argument. Pass kind="bar" for bars or leave it off for the default line.

df["sales"].plot(kind="bar")

Group Then Plot

A grouped summary plots beautifully because its index becomes the x-axis. Group, aggregate, then chain .plot.

df.groupby("region")["sales"].sum().plot(kind="bar")

Show the Figure

Outside a notebook you must call plt.show to pop the window. In Jupyter the chart appears on its own.

plt.show()

Size It Up

Tiny charts hide detail. Pass figsize as a width and height in inches to give your plot room to breathe.

df["sales"].plot(figsize=(8, 4))

Layer More Lines

Call plt.plot several times before showing and matplotlib stacks each line onto the same axes for easy comparison.

Clear Before You Redraw

Leftover plots can pile up across cells. Start fresh with plt.figure or close old ones so charts do not overlap.

Quick Check

You want to compare total sales across a few regions. Which chart fits best?

Recap: Your First Charts

You can now import plt, draw lines for trends and bars for categories, and plot straight from pandas. Your data has a face now! 🎨

Frequently asked questions

Is the “Line and Bar Charts in matplotlib” lesson free?

Yes — the full text of “Line and Bar Charts in matplotlib” is free to read here on the web, and the Data Science Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Data Science Academy course, upgrade to CoddyKit PRO.

What will I learn in “Line and Bar Charts in matplotlib”?

Plotting straight from a DataFrame. You practise Data Science Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Data Science Academy?

No prior experience is required. Data Science Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Line and Bar Charts in matplotlib” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Data Science Academy lesson?

Yes. Every Data Science Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Sort by One or Many Columns
  2. Your First groupby Summary
  3. Line and Bar Charts in matplotlib
  4. Labels, Titles, and Legends
← Back to Data Science Academy