Mathew K Analytics

Lesson 19 · Data visualisation in python

Mastering Custom Themes and Aesthetics in Seaborn for Clear Data Visualization

This lesson is all about making beautiful charts in Python using Seaborn. You will learn how to give your plots personal style. We will use real time series…

⬇ Download notebookOpen in Colab ↗

What you'll learn

Data

No separate download needed — the notebook creates or downloads everything it uses.

📓 Full notebook

Download .ipynb

Welcome to Custom Themes and Aesthetics in Seaborn#

This lesson is all about making beautiful charts in Python using Seaborn.

You will learn how to give your plots personal style.

We will use real time series data to make your charts really stand out.

Let us get started!

# First, silence all warnings to keep things tidy
import warnings
warnings.filterwarnings("ignore")

# Now import the essentials for plotting
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

Why learn themes and styles?#

Customizing your charts can help your data tell a clearer story.

It also makes your plots memorable and fun to share.

Let us explore how to do this.

# Data setup
# Let us load a simple time series: airline-passengers data
url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/airline-passengers.csv"
df = pd.read_csv(url)

# Check the data shape and the top rows
print("Data shape:", df.shape)
df.head()
Data shape: (144, 2)
Month Passengers
0 1949-01 112
1 1949-02 118
2 1949-03 132
3 1949-04 129
4 1949-05 121
# Let us make a quick line plot of the data
plt.figure(figsize=(8,4))
sns.lineplot(x="Month", y="Passengers", data=df)
plt.title("Airline Passengers Over Time")
plt.show()
No description has been provided for this image

What are plot themes and styles?#

A theme decides your plot's overall look: colors, grid, and background.

A style adds character: lines, fonts, and how things are arranged.

With Seaborn, you can change both with just one line of code.

# Let us try a built-in Seaborn theme: 'darkgrid'
sns.set_theme(style="darkgrid")
plt.figure(figsize=(8,4))
sns.lineplot(x="Month", y="Passengers", data=df)
plt.title("With Darkgrid Theme")
plt.show()
No description has been provided for this image
# Quickly explore all standard themes
styles = ["white", "dark", "whitegrid", "darkgrid", "ticks"]
for s in styles:
    sns.set_style(s)
    plt.figure(figsize=(5,2))
    sns.lineplot(x="Month", y="Passengers", data=df)
    plt.title(f"Style: {s}")
    plt.tight_layout()
    plt.show()
    
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image

Choosing colors#

Colors set the mood of your chart.

Seaborn gives you color palettes: collections of matching colors.

Let us try a few.

# Use Seaborn's set_palette to change the color set
sns.set_theme(style="whitegrid")
palettes = ["deep", "muted", "pastel", "bright", "dark", "colorblind"]
for p in palettes:
    sns.set_palette(p)
    plt.figure(figsize=(6,2))
    sns.lineplot(x="Month", y="Passengers", data=df, linewidth=2)
    plt.title(f"Palette: {p}")
    plt.tight_layout()
    plt.show()
    
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
# You can even create a custom palette from any colors you like!
custom = ["#f54272", "#4268f5", "#42f5a7"]
sns.set_palette(custom)
plt.figure(figsize=(8,4))
sns.lineplot(x="Month", y="Passengers", data=df, linewidth=2)
plt.title("Line Plot with a Custom Color Palette")
plt.show()
No description has been provided for this image

Font settings and plot text#

Clear and friendly fonts help your story.

Seaborn lets you set the font style and size easily.

Let us give it a try.

# Change font type and scale for a larger, friendlier look
sns.set_theme(font="Comic Sans MS", font_scale=1.2)
plt.figure(figsize=(8,4))
sns.lineplot(x="Month", y="Passengers", data=df, linewidth=2)
plt.title("Comic Sans for a Fun Vibe")
plt.show()
No description has been provided for this image
# Remove chart spines for a minimalist look
sns.set_style("white")
sns.set_palette("pastel")
plt.figure(figsize=(8,4))
ax = sns.lineplot(x="Month", y="Passengers", data=df, linewidth=2)
sns.despine()
plt.title("Minimalist Style: No Chart Spines")
plt.show()
No description has been provided for this image

Adjusting axes, labels, and ticks#

Small details matter, like spacing and label style.

This makes your chart easier to read.

Let us update some axis settings.

# Change label rotation and font for better reading
plt.figure(figsize=(8,4))
ax = sns.lineplot(x="Month", y="Passengers", data=df, linewidth=2, color="#4268f5")
ax.set_xticklabels(df["Month"], rotation=45, ha="right", fontsize=10)
ax.set_xlabel("Month", fontsize=12, fontweight="bold")
ax.set_ylabel("Passengers", fontsize=12, fontweight="bold")
plt.title("Angle and Style for Clear Axis Labels")
plt.tight_layout()
plt.show()
No description has been provided for this image
# Save your custom chart as a high-quality image
plt.figure(figsize=(8,4))
sns.set_theme(style="whitegrid", palette="deep")
sns.lineplot(x="Month", y="Passengers", data=df, linewidth=2)
plt.title("Ready to Share!")
plt.tight_layout()
plt.savefig("my_custom_passenger_plot.png", dpi=150)
plt.show()
print("Saved as my_custom_passenger_plot.png!")
No description has been provided for this image
Saved as my_custom_passenger_plot.png!

Quick troubleshooting tips#

  • If you see warnings, they are probably safe to ignore here.
  • If your font does not change, you may not have that font installed.
  • If a palette looks odd, check your color codes.

Google the exact error message for more details.

# Mini-project: Compare two years with custom aesthetics
# Task: Highlight changes by picking two years and custom styling
df["Year"] = df["Month"].str[:4]
years = ["1958", "1959"]
plt.figure(figsize=(8,4))
sns.lineplot(
    x="Month", y="Passengers", hue="Year",
    data=df[df["Year"].isin(years)],
    palette=["#ff7675", "#00b894"], linewidth=2)
plt.title("Passengers: 1958 vs. 1959 (Custom Colors)")
plt.xticks(rotation=40)
plt.tight_layout()
plt.show()
No description has been provided for this image
# Extra tip: Use 'context' to tune charts for slides or papers
for context in ["notebook", "paper", "talk", "poster"]:
    sns.set_context(context)
    plt.figure(figsize=(6,2))
    sns.lineplot(x="Month", y="Passengers", data=df)
    plt.title(f"Seaborn context: {context}")
    plt.tight_layout()
    plt.show()
    
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
# Final challenge: Try your own theme ideas!
style = input("Enter a Seaborn style (white, dark, whitegrid, darkgrid, ticks): ")
palette = input("Enter a Seaborn palette (deep, muted, pastel, bright, dark, colorblind): ")
font = input("Enter your favorite font (try Arial, Times New Roman): ")
sns.set_theme(style=style, palette=palette, font=font)
plt.figure(figsize=(8,4))
sns.lineplot(x="Month", y="Passengers", data=df, linewidth=2)
plt.title(f"Your Custom Theme: {style}, {palette}, {font}")
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
No description has been provided for this image

Recap: What did you learn today?#

  • How to change Seaborn chart themes and palettes
  • Customizing fonts, axes, and backgrounds
  • Saving and sharing your beautiful charts
  • Why style helps communicate your data story

With just a few lines, you can make charts that are clear and beautiful.

Thank you for learning with us!#

If you found this helpful, please like this video and subscribe.

Keep practicing and try more themes and palettes.

Happy coding!

Found this useful?

All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.