Which snack does your class love most: samosa, pani puri or vada pav? You could argue about it all lunch break. Or you could do what a data scientist does: collect data, count it, and draw a chart that settles the question in one glance.
In this tutorial you will turn a simple class survey into a clear, colourful bar chart using Python.
What is data science?
Data science is about using data (facts and numbers) to answer questions. It usually follows a simple path:
- Ask a question. "Which snack is most popular in our class?"
- Collect data. Ask everyone and write down the answers.
- Organise and calculate. Count the votes for each snack.
- Show it. Draw a chart so others can see the answer quickly.
- Tell the story. Say what you found, and what you cannot be sure about.
Cricket analysts, weather forecasters, doctors and businesses all follow some version of these steps.
Why charts?
Look at these numbers: Samosa 9, Pani puri 12, Dhokla 4, Vada pav 7, Idli 3. You can work out the winner, but it takes a moment. A bar chart shows the same data as bars of different heights. Your eyes spot the tallest bar instantly.
Bar charts are best when you compare categories, like types of snacks, cities or school houses. (For something that changes over time, like your height each year, a line chart is often better.)
A good chart always has:
- A clear title that says what it shows
- Axis labels so readers know what the numbers mean
- Bars that start from zero, so differences are not exaggerated
Try it: the snack survey chart
We will use matplotlib, the most widely used charting library in Python.
- Install it once with
pip install matplotlibin your terminal or command prompt. - Open a new Python file and type the program below.
- Run it. It prints a short summary and saves a picture called
snack_chart.pngin the same folder. - Open
snack_chart.pngto see your chart.
# My first chart: favourite snacks in our class
import matplotlib
matplotlib.use("Agg") # draw to a file, no window needed
import matplotlib.pyplot as plt
snacks = ["Samosa", "Pani puri", "Dhokla", "Vada pav", "Idli"]
votes = [9, 12, 4, 7, 3]
total = sum(votes)
top = snacks[votes.index(max(votes))]
print("Total votes:", total)
print("Most popular:", top, "with", max(votes), "votes")
plt.figure(figsize=(7, 4))
plt.bar(snacks, votes, color="#f28c28")
plt.title("Favourite snacks in Class 7B")
plt.xlabel("Snack")
plt.ylabel("Number of votes")
for i, v in enumerate(votes):
plt.text(i, v + 0.2, str(v), ha="center")
plt.tight_layout()
plt.savefig("snack_chart.png")
print("Chart saved as snack_chart.png")
The program prints:
Total votes: 35
Most popular: Pani puri with 12 votes
Chart saved as snack_chart.png
And your image shows five orange bars, with Pani puri clearly the tallest and each bar labelled with its vote count.
How the code works
snacksandvotesare two lists that line up: the first snack goes with the first number, and so on.sum(votes)adds up all the votes.max(votes)finds the biggest number, andvotes.index(...)tells us where it is, so we can look up the matching snack.plt.bar(...)draws the bars.plt.title,plt.xlabelandplt.ylabeladd the labels.- The
forloop writes each vote count just above its bar. plt.savefig(...)saves the chart as an image file.
Make it your own
- Collect real data. Survey your family, friends or class on something you care about: favourite sport, best festival sweet, how you travel to school.
- Replace the two lists with your data and run again.
- Change the colour. Try
"teal"or a code like"#4a90d9". - Sort the bars from highest to lowest so the chart is easier to read. (Hint: try putting the snacks in a different order in both lists.)
- Write two sentences about your chart: what it shows, and one thing it cannot tell you. For example, 35 votes from one class does not tell you what the whole school prefers.
For parents
Charts are everywhere: news, school reports, cricket broadcasts. Learning to make one also teaches children to read them critically, for example noticing a missing title or a misleading scale. Helping your child run a small family survey turns this into a real investigation they can present at dinner.
What you learned
- Data science means asking a question, collecting data, calculating, showing and explaining.
- Bar charts compare categories; a clear title and axis labels make them readable.
- Python lists can hold matching data, and
sumandmaxsummarise it. - matplotlib draws charts in a few lines and can save them as image files.
- A small sample can only answer a small question.
Take it further
One chart is a great start. In a full data science course, students load real datasets into tables with pandas, clean messy data, group and summarise it, choose the right chart for each question, and complete a full investigation. Want to build more? Book a free demo class and see how your child can turn questions into answers with data.