0Pricing
Python Academy · Lesson

Line, Bar and Scatter Plots

Create common chart types.

Line, Bar and Scatter Plots is a free Python Academy lesson on CoddyKit — lesson 2 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 Python Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Three Workhorse Charts

Most data stories are told with three chart types:

  • Line for trends over an ordered axis like time
  • Bar for comparing categories
  • Scatter for relationships between two numeric variables

Each maps to one Matplotlib method on an axes.

Line Plots

A line plot connects points in order. In Matplotlib it is ax.plot(x, y). Use it when the x-axis has a meaningful order, such as days or measurements over time.

The data behind a line is just two parallel sequences.

months = [1, 2, 3, 4, 5]
sales = [120, 150, 130, 170, 200]
for m, s in zip(months, sales):
    print('Month', m, '->', s)
print('Trend:', 'up' if sales[-1] > sales[0] else 'down')

Bar Charts

A bar chart compares discrete categories. The call is ax.bar(categories, values). Bars start from zero so their heights are directly comparable.

Use bars when the x positions are labels, not a continuous scale.

fruits = ['apple', 'banana', 'cherry']
counts = [30, 45, 15]
for f, c in zip(fruits, counts):
    bar = '#' * (c // 5)
    print(f.ljust(8), bar, c)

Horizontal Bars

When category labels are long, horizontal bars read better. Matplotlib offers ax.barh(categories, values).

The logic is identical, only the orientation changes.

Scatter Plots

A scatter plot draws one marker per data point with ax.scatter(x, y). It reveals correlation, clusters, and outliers between two numeric variables.

Unlike a line, points are not connected.

heights = [150, 160, 170, 180, 190]
weights = [50, 60, 68, 78, 90]
pairs = list(zip(heights, weights))
print('Points:', pairs)
rising = all(weights[i] < weights[i+1] for i in range(len(weights)-1))
print('Positive trend:', rising)

Choosing the Right Chart

Pick by the question you are answering:

  • How does a value change over time? Line
  • Which category is biggest? Bar
  • Are two variables related? Scatter

Choosing wrongly can mislead readers, for example using a line for unordered categories.

Multiple Series

You can call ax.plot() several times on the same axes to overlay multiple lines. Each call adds another series. Distinguish them later with a legend.

The same overlay idea works for scatter and combined chart types.

series_a = [1, 2, 3, 4]
series_b = [4, 3, 2, 1]
for i in range(len(series_a)):
    print('x', i, 'a', series_a[i], 'b', series_b[i])

Markers and Line Styles

Line plots accept a format string, for example ax.plot(x, y, 'o--') draws circle markers joined by a dashed line.

  • o circle marker
  • -- dashed line
  • r red color

These shortcuts make exploratory plots fast to tweak.

Grouped Bars

To compare two values per category, offset the bar positions. You shift one group by a small amount so the bars sit side by side.

The positions are computed with simple arithmetic on the index.

categories = ['Q1', 'Q2', 'Q3']
width = 0.4
for i, cat in enumerate(categories):
    left_pos = i - width / 2
    right_pos = i + width / 2
    print(cat, 'group A at', left_pos, 'group B at', right_pos)

Bubble Charts

A scatter plot can encode a third variable in marker size: ax.scatter(x, y, s=sizes). Larger bubbles mean larger values. This packs three dimensions into one chart.

Keep sizes reasonable so bubbles do not overlap into a blob.

Avoiding Misleading Charts

The chart type carries meaning, so the wrong choice can mislead. A line drawn over unordered categories implies a trend that does not exist. Bars that do not start at zero exaggerate differences.

Always ask whether the visual encoding matches the structure of your data.

Quick Check

Match the question to the right chart.

Recap

You now know the three core chart calls:

  • ax.plot(x, y) for trends over an ordered axis
  • ax.bar(cats, vals) for comparing categories
  • ax.scatter(x, y) for relationships, with s= for bubbles

Overlay multiple series on one axes and pick the type that matches your question.

Frequently asked questions

Is the “Line, Bar and Scatter Plots” lesson free?

Yes — the full text of “Line, Bar and Scatter Plots” is free to read here on the web, and the Python 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 Python Academy course, upgrade to CoddyKit PRO.

What will I learn in “Line, Bar and Scatter Plots”?

Create common chart types. You practise Python 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 Python Academy?

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

How long does the “Line, Bar and Scatter Plots” 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 Python Academy lesson?

Yes. Every Python 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. Figures and Axes
  2. Line, Bar and Scatter Plots
  3. Customizing Plots
  4. Subplots and Layouts
← Back to Python Academy