Lesson 41 · Data visualisation in python
Master Visual Design Principles for Effective Communication in Python Data Visualization
Welcome! In this lesson, you will learn Python by exploring visual design principles. No experience needed. We will use simple, real-world examples. You…
- CourseData visualisation in python
- Lesson41 of 34
- Video11 min
- FormatJupyter notebook · 21 code cells
What you'll learn
Data
No separate download needed — the notebook creates or downloads everything it uses.
📓 Full notebook
Download .ipynbVisual Design Principles for Effective Communication#
Welcome! In this lesson, you will learn Python by exploring visual design principles.
No experience needed. We will use simple, real-world examples.
You will see how to make data and messages clear and learn Python basics at the same time.
Let us get started!
import warnings
warnings.filterwarnings("ignore")
# Start by printing a simple hello message
print("Hello, welcome to visual design in Python!")
Why does visual design matter?#
Good design makes information easy to understand.
With Python, we can make charts to highlight patterns, trends, and stories in data.
You will learn important basics that help your ideas stand out.
# Variables hold information
title = "Monthly Airline Passengers"
year = 1950
print(title, year)
# Lists let us store groups of items
colors = ["red", "blue", "green", "yellow"]
print("Palette:", colors)
Visual Example: Loading Data#
We will use a real airline passenger dataset to practice.
This is a simple example of working with real-world data in Python.
# Data setup
import pandas as pd
url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/airline-passengers.csv"
data = pd.read_csv(url)
print(data.shape)
print(data.head())
# Plotting the data: first visualization
import matplotlib.pyplot as plt
plt.plot(data["Passengers"])
plt.title("Monthly Airline Passengers")
plt.xlabel("Month")
plt.ylabel("Number of Passengers")
plt.show()
Core Principle: Contrast#
Use contrast like color, size, or shape to draw attention to what matters.
Let us try using different colors in a chart.
# Highlighting with color
plt.figure()
plt.plot(data["Passengers"], color="purple")
plt.title("Passengers (Now in Purple)")
plt.xlabel("Month")
plt.ylabel("Number of Passengers")
plt.show()
# Safe access and error: What if column is missing?
try:
print(data["NotAColumn"].head())
except KeyError:
print("That column is not in the data.")
Editing Data: Make Simple Changes#
Good design means always checking your raw data.
Let us update a value to show how.
# Change the number in the top row
print("Before:", data.loc[0, "Passengers"])
data.loc[0, "Passengers"] = 120
print("After:", data.loc[0, "Passengers"])
# Removing extra rows - cleaning up
before_rows = len(data)
data = data.drop(data.index[-1])
after_rows = len(data)
print("Rows before:", before_rows, "Rows after:", after_rows)
# Useful summary: statistics methods
print("Mean passengers:", data["Passengers"].mean())
print("Biggest month:", data["Passengers"].max())
print("Smallest month:", data["Passengers"].min())
# Looping: print months with high passenger numbers
for i, row in data.iterrows():
if row["Passengers"] > 400:
print(row["Month"], "had more than 400 passengers.")
# List comprehension: find very busy months
busy_months = [row["Month"] for i, row in data.iterrows() if row["Passengers"] > 450]
print("Busy months:", busy_months)
# Sorting: see top months
sorted_data = data.sort_values("Passengers", ascending=False)
print(sorted_data.head(3))
Combining Data: Add a Design Column#
You can combine new information with your data. Let us mark busy months with a tag.
This is useful for labeling key features in a chart.
# Tagging busy months for highlighting
data["Busy"] = data["Passengers"] > 400
print(data[["Month", "Passengers", "Busy"]].head())
# Real-world chart: color by busy tag
colors = ["red" if busy else "skyblue" for busy in data["Busy"]]
plt.figure(figsize=(12,5))
plt.bar(data["Month"], data["Passengers"], color=colors)
plt.xticks(rotation=90)
plt.title("Passengers per Month: Busy in Red")
plt.ylabel("Number of Passengers")
plt.tight_layout()
plt.show()
# Mini-project part 1: Ask the user for a key month to highlight
special_month = input("Which month do you think is important? ")
data["Special"] = data["Month"] == special_month
print("Special month set:", special_month)
# Mini-project part 2: Show the special month in gold
colors = ["gold" if special else ("red" if busy else "skyblue") for busy, special in zip(data["Busy"], data["Special"])]
plt.figure(figsize=(12,5))
plt.bar(data["Month"], data["Passengers"], color=colors)
plt.xticks(rotation=90)
plt.title("Passengers per Month: Highlighted")
plt.ylabel("Number of Passengers")
plt.tight_layout()
plt.show()
# Best practices: clear labels and colorblind-friendly palettes
plt.figure(figsize=(10,4))
cb_colors = ["#000000" if special else ("#0072B2" if busy else "#E69F00") for busy, special in zip(data["Busy"], data["Special"])]
plt.bar(data["Month"], data["Passengers"], color=cb_colors)
plt.title("Accessible Design: Clear and Friendly Colors")
plt.xlabel("Month")
plt.ylabel("Passengers")
plt.tight_layout()
plt.show()
# Troubleshooting: what if user picks a missing month?
try:
if not data["Special"].any():
raise ValueError("Month not found.")
except ValueError:
print("That month does not exist. Please check your spelling or format.")
# Extra tip: Export your improved data to a new file
data.to_csv("improved_airline_design.csv", index=False)
print("CSV saved!")
# Challenge: Mark all months above a custom passenger count
threshold = int(input("Enter a number to set your own busy level: "))
data["YourBusy"] = data["Passengers"] > threshold
print(data[["Month", "YourBusy"]].head())
Recap#
You learned how to:
- Create and edit data
- Make basic and advanced charts
- Use design tricks for clarity and impact
- Handle user input and common errors
Good design helps your message stand out.
Now you have the tools to make a difference with Python!
Thank you for following along!
If you enjoyed learning, please like this video and subscribe for more lessons.
Happy coding and see you next time!
Found this useful?
All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.



