SAMANTUS Python for Data Analytics — Complete Training Manual MODULE 15
← Back to Course Index

Data Visualization


On This Page

Module 15: Data Visualization


15.1  Why Data Visualization Matters

A chart can communicate a business insight in 2 seconds that would take 200 rows of numbers to explain. Matplotlib is Python's foundational plotting library, and Seaborn builds on top of it with more attractive, statistically-aware charts.

► Installing & Importing
pip install matplotlib seaborn

import matplotlib.pyplot as plt
import seaborn as sns

All charts in this module use a sample dataset from Samantus Institute's own monthly revenue, course enrollments, and student performance records.

15.2  Line Chart

Line charts are best for showing trends over time — perfect for tracking revenue, growth, or performance month over month.

► Line Chart Syntax
months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug"]
revenue = [180000,195000,210000,205000,230000,250000,265000,280000]

plt.plot(months, revenue, marker="o", color="orange")
plt.title("Monthly Revenue Trend")
plt.xlabel("Month"); plt.ylabel("Revenue (Rs.)")
plt.show()
Figure 15.1 — Monthly revenue trend for Samantus Institute, Jan-Aug 2026.
Figure 15.1 — Monthly revenue trend for Samantus Institute, Jan-Aug 2026.
ℹ Interpretation
Revenue shows a consistent upward trend from Jan (Rs.1.8L) to Aug (Rs.2.8L), with only one minor dip in April — suggesting effective marketing and steady student acquisition through the year.

15.3  Bar Chart

Bar charts compare quantities across categories — ideal for comparing enrollment counts across different courses.

► Bar Chart Syntax
courses = ["SEO","Google Ads","Meta Ads","Web Design","AI Tools"]
enrollments = [45, 38, 42, 28, 55]

plt.bar(courses, enrollments, color=["navy","orange","blue","green","purple"])
plt.title("Student Enrollments by Course")
plt.show()
Figure 15.2 — Student enrollment counts across 5 course categories.
Figure 15.2 — Student enrollment counts across 5 course categories.
ℹ Interpretation
AI Tools has the highest enrollment (55 students), overtaking traditional favourites like SEO — a clear signal to allocate more batches and marketing budget toward AI-related courses.

15.4  Pie Chart

Pie charts show proportions of a whole — best used with a small number of categories (5 or fewer).

► Pie Chart Syntax
plt.pie(enrollments, labels=courses, autopct="%1.1f%%")
plt.title("Course Enrollment Share (%)")
plt.show()
Figure 15.3 — Percentage share of total enrollments by course.
Figure 15.3 — Percentage share of total enrollments by course.
✗ Common Mistake
Avoid pie charts with more than 5-6 categories — the slices become too small to compare meaningfully. Use a bar chart instead for larger category counts.

15.5  Histogram

Histograms show the distribution of a single numeric variable — how values are spread across ranges.

► Histogram Syntax
plt.hist(marks, bins=15, color="steelblue", edgecolor="white")
plt.title("Distribution of Student Marks")
plt.xlabel("Marks"); plt.ylabel("Number of Students")
plt.show()
Figure 15.4 — Distribution of marks across 200 students.
Figure 15.4 — Distribution of marks across 200 students.
ℹ Interpretation
The distribution is roughly bell-shaped (normal), centered around 75-80 marks — indicating consistent teaching quality with most students performing near the class average.

15.6  Scatter Plot

Scatter plots reveal the relationship between two numeric variables — used to spot correlations and patterns.

► Scatter Plot Syntax
plt.scatter(ages, study_hours, color="orange", edgecolor="navy")
plt.title("Age vs Weekly Study Hours")
plt.xlabel("Age"); plt.ylabel("Study Hours per Week")
plt.show()
Figure 15.5 — Relationship between student age and weekly study hours.
Figure 15.5 — Relationship between student age and weekly study hours.
ℹ Interpretation
There is a mild positive relationship — slightly older students tend to log a few more study hours per week, though the spread shows this is not a strong or guaranteed pattern.

15.7  Heatmap

Heatmaps visualize a matrix of values using color intensity — most commonly used to display correlation between multiple numeric variables at once.

► Heatmap Syntax
corr = df[["Study_Hours","Attendance","Marks","Assignments"]].corr()
sns.heatmap(corr, annot=True, cmap="Oranges")
plt.title("Correlation Heatmap")
plt.show()
Figure 15.6 — Correlation heatmap between study habits and exam performance.
Figure 15.6 — Correlation heatmap between study habits and exam performance.
ℹ Interpretation
Marks correlate strongly with both Study_Hours and Attendance (values close to 1.0), confirming that these two factors are the biggest drivers of student performance in this dataset.

15.8  Box Plot

Box plots show the spread, median, and outliers of a numeric variable, often split by category — extremely useful for spotting unusual data points.

► Box Plot Syntax
sns.boxplot(data=df, x="Course", y="Score")
plt.title("Score Distribution & Outliers by Course")
plt.show()
Figure 15.7 — Score spread and outliers across 5 courses.
Figure 15.7 — Score spread and outliers across 5 courses.
ℹ Interpretation
AI Tools students show the highest median score with a tight spread, while Web Design shows wider variation — suggesting a need to review the Web Design curriculum's consistency.

15.9  Pair Plot

A pair plot shows scatter plots between every combination of numeric columns at once — a fast way to spot multiple relationships in one view.

► Pair Plot Syntax
sns.pairplot(df, hue="Course")
plt.show()
Figure 15.8 — Pair plot of Study Hours, Attendance %, and Marks, colored by Course.
Figure 15.8 — Pair plot of Study Hours, Attendance %, and Marks, colored by Course.
✓ Instructor Tip
Pair plots are best introduced right before EDA (Module 16) — they are often the very first visualization a data analyst creates on any brand-new dataset.

15.10  Choosing the Right Chart

GoalBest Chart
Show a trend over timeLine Chart
Compare categoriesBar Chart
Show proportion of a whole (few categories)Pie Chart
Show distribution of one variableHistogram
Show relationship between 2 variablesScatter Plot
Show relationships between many variables at onceHeatmap / Pair Plot
Show spread & outliers by categoryBox Plot

15.11  Practical Exercises

Basic (5 Questions)

1. Create a line chart showing your own 6-month sample expense data.

2. Create a bar chart comparing marks of 5 students.

3. Create a pie chart showing the % split of your daily activities (study, work, rest, etc.).

4. Create a histogram of 50 random exam scores.

5. Create a scatter plot of hours studied vs marks scored for 15 students.

Intermediate (5 Questions)

1. Add titles, axis labels, and a legend to any 2 charts from the Basic section.

2. Create a heatmap showing the correlation between 4 numeric columns of a sample dataset.

3. Create a box plot comparing exam scores across 3 different classes/sections.

4. Combine a bar chart and line chart on the same figure using two y-axes (advanced formatting).

5. Create a pair plot for a 3-column numeric dataset and describe one insight from it.

Advanced (5 Questions)

1. Build a complete 'Monthly Sales Dashboard' with 3 charts: line (trend), bar (by category), and pie (share).

2. Create a heatmap-based correlation analysis for a real dataset with at least 5 numeric columns.

3. Build a box plot comparing student performance across 4+ courses and write a 3-sentence interpretation.

4. Create a scatter plot with a trend line (using seaborn's regplot) and interpret the relationship.

5. Design a full one-page visual report combining 4 different chart types for a sample business dataset of your choice.

15.12  Module Quiz (MCQs)

Q1. Which chart is best for showing a trend over time?

Q2. Which chart should be avoided with more than 6 categories?

Q3. Which chart shows the distribution of one numeric variable?

Q4. Which chart is best for spotting outliers?

Q5. Which library builds on top of Matplotlib with more advanced statistical charts?

ℹ Answer Key
1-b, 2-c, 3-b, 4-c, 5-c

15.13  Module Assignment

Assignment: Institute Performance Visual Report

Expected Output: A complete 4-chart visual performance report with clear titles, labels, and a written business interpretation.

15.14  Interview Questions — Module 15


15.15  Student Notes Page

Use this space to write down key points, doubts, and your own examples from today's session.