KwickAcademy Python · 7 min · free
Data Visualisation with Matplotlib
Learn data visualisation with Matplotlib in Python: draw line plots, bar charts and histograms, add titles, labels and legends, and save a figure.
On screen in this lesson
Why visualise data?
| Visualise: turn numbers into a picture |
| See a trend: going up or going down |
| Compare groups quickly |
| Spot unusual values at a glance |
Getting Matplotlib ready
| Matplotlib: a library for drawing charts |
| Install once: pip install matplotlib |
| pyplot: the part we use to draw |
| import matplotlib.pyplot as plt |
Bar chart vs histogram
| Point | Bar chart | Histogram |
|---|---|---|
| Data | named groups | numbers in ranges |
| Bars | have gaps | touch each other |
| Example | sales per item | marks spread |
| Function | plt.bar() | plt.hist() |
Saving: common mistakes
| Call savefig() before show() |
| After show() closes, the figure is empty |
| Add title and labels before saving |
| dpi=200 gives a sharper image |
Choosing the right chart
| Your data | Question | Chart |
|---|---|---|
| Values over time | Is it rising? | Line plot |
| Named groups | Which is biggest? | Bar chart |
| Many numbers | How spread out? | Histogram |
| Parts of one whole | What share? | Pie chart |
Quick recap
| Charts show trends, comparisons and odd values |
| plot() for time, bar() for groups, hist() for spread |
| title(), xlabel(), ylabel() and legend() explain it |
| savefig() before show() |
| Pick the chart that answers your question |
Quick answers
What is the difference between a bar chart and a histogram?
A bar chart shows named groups; a histogram shows numbers grouped into ranges, and its bars touch.
Why must savefig() come before show()?
After the show window closes the figure is cleared, so saving then gives a blank image.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
Why use a chart instead of a table?40 sec
Is a bar chart the same as a histogram?41 sec
How do you show which line is whose?42 sec
Why is my saved Matplotlib image blank?40 sec
Which chart suits monthly rainfall?41 secThe full lesson, in text
Hello students, welcome to Kwickprep. A month of test scores is just a long list of numbers. Can you spot the pattern by reading them? A chart makes it easy. Today we will draw line plots, bar charts and histograms in Python, label them, save them, and choose the right chart.
First, what does visualise mean? To visualise data means to turn numbers into a picture, like a chart. A line going up or down shows a trend straight away. Bars side by side let us compare groups quickly. A value that is far away from the others stands out at a glance. That is why news channels and cricket broadcasts show charts, not long tables.
Matplotlib is a Python library for drawing charts. A library is ready-made code that you add to Python. You install it once with pip install matplotlib. Inside it, a part called pyplot has the drawing tools. We write import matplotlib dot pyplot as p l t, so p l t becomes its short name.
A line plot joins points with a line. It is best for data that changes over time. Here, tests one to five go along the bottom, called the x axis. Riya's marks go up the side, called the y axis. P l t dot plot draws the line, and p l t dot show opens the chart window. The line goes up, so Riya is improving.
A bar chart uses bars to compare separate groups. Here the groups are canteen items, and the bar height shows how many were sold in a day. P l t dot bar takes the names and the numbers. One look tells us tea sold the most, and vada pav the least.
A histogram shows how numbers are spread across ranges. The ranges are called bins. Here m is a list of eight students' marks, and the bins are zero to forty, forty to sixty, and so on. P l t dot hist counts how many marks fall in each bin, and index zero of its result is those counts. Pause and predict. Which bin gets the mark of exactly forty? The forty to sixty bin, because each bin includes its left edge. Only the last bin also includes its right edge, so one hundred is counted. Add p l t dot show to see the bars.
Bar charts and histograms look alike, so exams often ask the difference. A bar chart shows named groups, while a histogram shows numbers grouped into ranges. Bar chart bars usually have gaps, but histogram bars touch. Sales per canteen item suits a bar chart, and the spread of class marks suits a histogram. In code, we use p l t dot bar and p l t dot hist.
A chart without words is a puzzle. P l t dot title adds a heading at the top. X label names the bottom axis, and y label names the side axis. Marker equals o puts a dot on every point. Now anyone can read the chart without asking you. Add p l t dot show at the end to see it.
When a chart has two lines, which line is whose? A legend is the small box that names each line. First, give every plot a label. Then call p l t dot legend to show the box. Forget the labels, and Matplotlib warns that it found no labels, so the legend stays empty. When we give only one list, Matplotlib numbers the x axis from zero.
To use a chart in a project report, save it as an image. P l t dot savefig saves the chart to a file, here sales dot p n g. The os module can check files, and os dot path dot exists prints True, so the file was saved. You can also save as a P D F or a J P G by changing the ending of the name.
Here are rules that save you from a blank image. Always call savefig before show. After the show window closes, the figure is cleared, so saving then gives an empty picture. Add the title and labels first, because savefig saves only what is already drawn. For a sharper picture, add d p i equals two hundred, which means more dots per inch.
How do you choose the right chart? Start with the question you want to answer. For values over time, like monthly rainfall, use a line plot. For named groups, like votes per house team, use a bar chart. For many numbers, like the heights of a class, use a histogram. For parts of one whole, like how you spend your pocket money, a pie chart works, made with p l t dot pie.
Let us revise what we learned today. Charts show trends, comparisons and unusual values quickly. Use plot for change over time, bar for groups, and hist for spread. Title, x label, y label and legend explain the chart. Always call savefig before show. And pick the chart that answers your question. Try drawing a bar chart of your own weekly screen time.
Courses that teach this
| Course | Unit |
|---|---|
| CBSE Class 10 Artificial Intelligence (417) | Part B Unit 4: Statistical Data / Data Sciences |
| CBSE Class 12 Informatics Practices (065) | Data Handling using Pandas -I |
| CBSE Class 11 Artificial Intelligence (843) | Data Literacy — Data Collection to Data Analysis |
| GSEB Std 10 Computer Studies | Spreadsheets with LibreOffice Calc |
| Programming All levels Python | Working with Data (Intro Libraries) |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

