Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 37 · Collecting and Displaying Data

Bar Charts and Pie Charts

Learn to draw and read bar charts, dual bar charts and pie charts, calculate pie angles, and spot misleading graphs, with matplotlib examples to run.

A good chart lets the eye see in a second what a table needs a minute to show. Bar charts and pie charts are the two classic displays for categorical and discrete data. This lesson shows you how to draw and read both, and how to avoid the common traps.

Bar charts

A bar chart has one bar per category. The height of each bar equals its frequency. Rules for a good bar chart:

  • Equal width for all bars, with equal gaps between them.
  • A vertical axis that starts at 0.
  • Labels on both axes and a title.
  • Bars arranged in a sensible order (alphabetical, by size, or in natural order for ordinal data).
Python A simple bar chart

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

For discrete numerical data such as the number of siblings, the bars may be placed on the number line. They are still separated, because the values are separate. (In a histogram, covered in the next lesson, bars touch because the data are continuous.)

Dual and stacked bar charts

A dual (grouped) bar chart places two bars side by side per category to compare two groups, for example boys and girls. A stacked bar chart stacks the groups, which makes the total easy to see but individual groups harder to compare.

Python A dual bar chart

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Pie charts

A pie chart shows how a whole is split into parts. The whole circle is 360°, and each category gets a sector whose angle is proportional to its frequency.

angle = (frequency / total) × 360°

Example: of 40 students, 18 walk to school. The angle is 18/40 × 360° = 162°.

Travel Frequency Angle
Walk 18 162°
Bus 12 108°
Car 6 54°
Bike 4 36°
Total 40 360°

The angles must add to 360°. If they do not, check your arithmetic. The ratio 360 / 40 = 9° per student gives a shortcut here: each student is worth 9°.

Python Pie angles and a pie chart

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Bar chart or pie chart?

Use a pie chart when... Use a bar chart when...
You show parts of one whole You compare categories or groups
There are about 2 to 6 categories There are many categories
Percent shares matter most Exact values or small differences matter

Pie charts make it hard to compare slices of similar size. When in doubt, choose the bar chart.

Spotting misleading charts

  • Truncated axis. A bar chart that begins at 50 makes a difference between 52 and 56 look huge.
  • 3D effects distort areas, so avoid them.
  • Unequal bar widths make the eye judge area rather than height.
  • Missing labels or units make a chart meaningless.

When you see a striking chart, check the axis start, the units and the source before you believe the story it tells.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. In a survey of 60 people, 15 prefer tea. What is the pie chart angle for tea?

    15/60 × 360° = 90°.
  2. 2. Which rule must a bar chart follow?

    A zero baseline keeps bar heights proportional to the values.
  3. 3. A pie chart is best for showing

    Pie charts show shares of a total. Many categories or trends are better shown another way.
  4. 4. The sector angles of a correct pie chart add up to

    The sectors fill the whole circle, which is 360°.

Summary

  • Bar charts show frequency by bar height; start the axis at 0 and keep bars equal in width.
  • Dual bar charts compare groups; stacked bars show totals.
  • Pie angle = frequency / total × 360°, and all angles sum to 360°.
  • Watch for truncated axes, 3D effects and missing labels.

Next: Histograms and Grouped Data