Lesson 12 · Data visualisation in python
Enhancing Matplotlib Plots: Mastering Colors, Markers, and Line Styles in Python
This lesson will guide you, step-by-step, through making your plots stand out using simple tweaks. You will learn how to: Add color to lines and points Use…
- CourseData visualisation in python
- Lesson12 of 34
- Video15 min
- FormatJupyter notebook · 15 code cells
What you'll learn
Data
No separate download needed — the notebook creates or downloads everything it uses.
📓 Full notebook
Download .ipynbWelcome to: Styling Plots in Python Colors, Markers, and Line Styles#
This lesson will guide you, step-by-step, through making your plots stand out using simple tweaks.
You will learn how to:
- Add color to lines and points
- Use markers to highlight data
- Change line styles to make differences clear
No prior experience is needed. Let us make your charts pop!
import warnings
warnings.filterwarnings("ignore")
# Let us import all the main packages for plotting.
import matplotlib.pyplot as plt
import pandas as pd
Why style your plots?#
Good styling helps highlight key points and makes your plots easier to read.
We will work with a real-world time series dataset to see the effect of each style change.
# Data setup: Let us load the Daily Minimum Temperatures dataset.
url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/daily-min-temperatures.csv"
data = pd.read_csv(url)
print("Shape:", data.shape)
data.head()
# Let us plot the temperatures as a simple line chart.
plt.figure(figsize=(10,4))
plt.plot(data["Date"], data["Temp"])
plt.title("Daily Minimum Temperatures - Raw Plot")
plt.xlabel("Date")
plt.ylabel("Min Temperature (C)")
plt.show()
Adding Color to Lines#
A pop of color helps points and lines jump out. Let us try it!
# Let us plot with a red line.
plt.figure(figsize=(10,4))
plt.plot(data["Date"], data["Temp"], color="red")
plt.title("Temperatures with Red Line")
plt.xlabel("Date")
plt.ylabel("Min Temperature (C)")
plt.show()
# Picking your own color using input().
color_choice = input("Type a color name (e.g. 'purple', 'orange', or a hex like '#00FFFF'): ")
plt.figure(figsize=(10,4))
plt.plot(data["Date"], data["Temp"], color=color_choice)
plt.title(f"Temperatures in {color_choice}")
plt.xlabel("Date")
plt.ylabel("Min Temperature (C)")
plt.show()
Markers: Making Points Pop#
Markers add shapes at each data point, making it easy to spot values.
Let us see how markers work.
# Plot only the first 31 points with circles as markers.
first_month = data.iloc[:31]
plt.figure(figsize=(8,4))
plt.plot(first_month["Date"], first_month["Temp"], marker="o", color="navy")
plt.title("One Month: Blue Circles as Markers")
plt.xlabel("Date")
plt.ylabel("Min Temperature (C)")
plt.show()
# Combine different marker styles to compare two weeks.
plt.figure(figsize=(8,4))
plt.plot(first_month["Date"][:7], first_month["Temp"][:7], marker="s", color="green", label="Week 1")
plt.plot(first_month["Date"][7:14], first_month["Temp"][7:14], marker="^", color="magenta", label="Week 2")
plt.title("First Two Weeks with Different Markers")
plt.xlabel("Date")
plt.ylabel("Min Temperature (C)")
plt.legend()
plt.show()
Line Styles: Dash, Dot, and More#
Change the line look to show differences or patterns.
Dashed or dotted lines are easy to makelet us see how!
# Try a dashed line with plt.plot(..., linestyle="--")
plt.figure(figsize=(10,4))
plt.plot(data["Date"][:62], data["Temp"][:62], linestyle="--", color="crimson", marker="o")
plt.title("Dashed Line with Circles Two Months of Data")
plt.xlabel("Date")
plt.ylabel("Min Temperature (C)")
plt.show()
# Mix solid, dashed, and dotted lines together.
plt.figure(figsize=(10,4))
plt.plot(data["Date"][:15], data["Temp"][:15], linestyle="-", color="blue", marker="o", label="Solid")
plt.plot(data["Date"][15:31], data["Temp"][15:31], linestyle=":", color="red", marker="s", label="Dotted")
plt.plot(data["Date"][31:46], data["Temp"][31:46], linestyle="--", color="teal", marker="^", label="Dashed")
plt.title("Line Styles Side by Side")
plt.xlabel("Date")
plt.ylabel("Min Temperature (C)")
plt.legend()
plt.show()
Style Shortcuts The 'fmt' Code#
Short style codes let you set color, marker, and line style in one short string.
Try 'go--' for green circles dashed, 'r*:' for red stars dotted.
This is quick, but sometimes less clear than using named arguments.
# Plot with format codes: 'm^--' means magenta, triangles, dashed.
plt.figure(figsize=(8,4))
plt.plot(first_month["Date"][:14], first_month["Temp"][:14], "m^--")
plt.title("Two Weeks Magenta Triangles Dashed")
plt.xlabel("Date")
plt.ylabel("Min Temperature (C)")
plt.show()
# Practice: Pick marker, color, line style with input().
your_color = input("Type a color (e.g. 'orange'): ")
your_marker = input("Marker code (e.g. 'o' for circle, 's' for square): ")
your_linestyle = input("Line style code ('-', '--', ':', '-.'): ")
plt.figure(figsize=(8,4))
plt.plot(first_month["Date"], first_month["Temp"], color=your_color, marker=your_marker, linestyle=your_linestyle)
plt.title("Your Custom Styles")
plt.xlabel("Date")
plt.ylabel("Min Temperature (C)")
plt.show()
Real-World Example: Compare Seasons#
Let us see how different styles help compare summer and winter.
# Find summer (Dec-Feb) and winter (Jun-Aug) temperatures in Australia.
data["Date"] = pd.to_datetime(data["Date"])
summer = data[data["Date"].dt.month.isin([12,1,2])].iloc[:90]
winter = data[data["Date"].dt.month.isin([6,7,8])].iloc[:90]
plt.figure(figsize=(10,4))
plt.plot(summer["Date"], summer["Temp"], color="red", linestyle=":", marker="*", label="Summer")
plt.plot(winter["Date"], winter["Temp"], color="blue", linestyle="--", marker="o", label="Winter")
plt.title("Summer vs. Winter Temperatures with Style")
plt.xlabel("Date")
plt.ylabel("Min Temperature (C)")
plt.legend()
plt.show()
Mini-project Step 1: Plot a Weekly Average with Style#
Let us create a new line showing a moving weekly average, and style it.
# Make a 7-day rolling average, then plot with thick green dashed line.
data["Rolling"] = data["Temp"].rolling(window=7).mean()
plt.figure(figsize=(10,4))
plt.plot(data["Date"], data["Temp"], color="lightgray", label="Daily", alpha=0.7)
plt.plot(data["Date"], data["Rolling"], color="green", linestyle="--", linewidth=3, label="Weekly Avg")
plt.title("7-Day Rolling Average Styled Line")
plt.xlabel("Date")
plt.ylabel("Min Temperature (C)")
plt.legend()
plt.show()
Mini-project Step 2: Custom Chart Challenge#
Now, it is your turn! Make a plot with your favorite color, marker, and line style, and add your name to the chart title.
Use the input below to create your own signature plot.
# Design your own plot with your name in the title.
your_color = input("Color: ")
your_marker = input("Marker: ")
your_style = input("Line style: ")
your_name = input("Your first name: ")
plt.figure(figsize=(9,4))
plt.plot(data["Date"][:90], data["Temp"][:90], color=your_color, marker=your_marker, linestyle=your_style)
plt.title(f"{your_name}'s Styled Plot First 90 Days")
plt.xlabel("Date")
plt.ylabel("Min Temperature (C)")
plt.show()
Tips for Beautiful Plots#
- Use dark backgrounds for colors that pop.
- Do not use too many marker types on one plot.
- When comparing groups, pick colors that are easy to tell apart.
- Keep titles and labels short and clear.
# Quick troubleshooting: What if my plot gives errors?
# - Double-check your color name, marker, or linestyle for typos.
# - Make sure numbers and labels match up in your data.
# - If nothing shows, try re-running the cell.
Challenge: Mix-and-Match Styles#
Try plotting the temperatures for each month in a different style.
Use at least three different colors, markers, and line types.
See how quickly viewers can tell apart separate months!
What we learned#
You can now use color, markers, and line styles to make any chart look great!
Try mixing styles until you find what tells the story you want readers to see.
Thank you for learning with us.
Want more like this?#
Hit 'Like' and 'Subscribe' to get friendly Python lessons every week.
Share your styled charts or questions in the video comments below!
See you next lesson.
Found this useful?
All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.



