Lesson 3 - Customizing Plots
Making Professional Visualizations
You can create basic plots. Now you will learn customization—transforming plain graphs into professional, informative visualizations that communicate insights clearly.
By the end of this lesson, you will be able to:
- Remove scientific notation from axes for better readability
- Add titles and axis labels to graphs
- Customize line colors, styles, and markers
- Create professional-looking visualizations
- Combine multiple customizations effectively
A graph without labels is like a book without a title—you do not know what it is about. Professional graphs always include proper titles, labels, and styling.
Removing Scientific Notation
In the previous lesson, we saw large numbers displayed in scientific notation (like 7.5e6). While technically correct, it is harder for most people to read.
Why This Matters
- Scientific notation:
7.5e6requires mental calculation - Regular notation:
7,500,000is instantly understandable - Makes graphs more accessible to non-technical audiences
We can fix this with plt.ticklabel_format():
import matplotlib.pyplot as plt
# COVID-19 new cases data (January - July 2020)
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul']
new_cases = [292219, 852102, 858350, 3027042, 3633886, 7823289, 7879833]
# Create the plot
plt.plot(months, new_cases)
# Remove scientific notation from y-axis
plt.ticklabel_format(axis='y', style='plain')
plt.show()Understanding the Code
axis='y'- applies to y-axis (can also use'x'or'both')style='plain'- uses regular numbers instead of scientific notation
Now the y-axis displays regular numbers that anyone can read immediately.
Adding Titles and Labels
A professional graph needs three key text elements:
- Title - What the graph shows
- X-axis label - What the horizontal axis represents
- Y-axis label - What the vertical axis represents
Adding All Three Elements
import matplotlib.pyplot as plt
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul']
new_cases = [292219, 852102, 858350, 3027042, 3633886, 7823289, 7879833]
plt.plot(months, new_cases)
plt.ticklabel_format(axis='y', style='plain')
# Add title and labels
plt.title('Global COVID-19 New Cases (January - July 2020)')
plt.xlabel('Month')
plt.ylabel('New Cases')
plt.show()Best Practices for Labels
Title:
- Should be descriptive but concise
- Summarizes what the graph shows
- Use title case for better readability
Axis Labels:
- Include units if applicable (e.g., “Temperature (Celsius)”, “Revenue ($)”)
- Keep them short and clear
- Capitalize appropriately
Example labels with units:
plt.ylabel('Temperature (°F)')
plt.ylabel('Revenue ($)')
plt.ylabel('Distance (km)')
plt.xlabel('Time (hours)')Customizing Line Colors
The default blue line is fine, but sometimes you want to:
- Match your company’s branding colors
- Make the line stand out more
- Use color to convey meaning (red for danger, green for growth)
You can change the color using the color parameter:
import matplotlib.pyplot as plt
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul']
new_cases = [292219, 852102, 858350, 3027042, 3633886, 7823289, 7879833]
# Red line to show alarming trend
plt.plot(months, new_cases, color='red')
plt.ticklabel_format(axis='y', style='plain')
plt.title('Global COVID-19 New Cases (January - July 2020)')
plt.xlabel('Month')
plt.ylabel('New Cases')
plt.show()Common Color Options
Named colors:
'red','blue','green','orange','purple','black','gray'
Short codes:
'r'(red),'b'(blue),'g'(green),'k'(black),'m'(magenta),'c'(cyan),'y'(yellow)
Hex codes (for exact colors):
'#FF5733','#3498DB','#2ECC71'
Tip: You can find hex color codes at colorpicker.com or similar websites.
Using Color Meaningfully
- Red: Warnings, danger, negative trends
- Green: Growth, positive trends, success
- Blue: Neutral, professional, trust
- Orange: Attention, moderate concern
- Purple: Premium, special categories
Customizing Line Styles and Markers
Beyond color, you can customize:
- Line style - solid, dashed, dotted
- Markers - points at each data value
- Line width - thicker or thinner lines
Dashed Line with Markers
import matplotlib.pyplot as plt
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul']
new_cases = [292219, 852102, 858350, 3027042, 3633886, 7823289, 7879833]
# Dashed line with circular markers
plt.plot(months, new_cases,
color='red',
linestyle='--', # Dashed line
marker='o') # Circular markers
plt.ticklabel_format(axis='y', style='plain')
plt.title('Global COVID-19 New Cases (January - July 2020)')
plt.xlabel('Month')
plt.ylabel('New Cases')
plt.show()Line Style Options
| Style | Code | Description |
|---|---|---|
| Solid | '-' or 'solid' | Solid line (default) |
| Dashed | '--' or 'dashed' | Dashed line |
| Dotted | ':' or 'dotted' | Dotted line |
| Dash-dot | '-.' or 'dashdot' | Alternating dash and dot |
Marker Options
| Marker | Code | Description |
|---|---|---|
| Circle | 'o' | Circular marker |
| Square | 's' | Square marker |
| Triangle | '^' | Triangle pointing up |
| Star | '*' | Star marker |
| Diamond | 'D' | Diamond marker |
| Plus | '+' | Plus sign |
| X | 'x' | X marker |
When to Use Markers
- When you have few data points (< 20)
- To emphasize individual values
- To make the line more visible
- To distinguish multiple lines
Adjusting Line Width
# Thicker dotted line with square markers
plt.plot(months, new_cases,
color='purple',
linestyle=':',
marker='s',
linewidth=2) # Thicker line
plt.ticklabel_format(axis='y', style='plain')
plt.title('Global COVID-19 New Cases (January - July 2020)')
plt.xlabel('Month')
plt.ylabel('New Cases')
plt.show()Line width values:
- Default:
1.0 - Thin:
0.5 - Thick:
2.0or3.0
Practice Exercises
Apply customization techniques with these exercises.
Exercise 1: Sales Report
You have monthly sales data for your company:
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
sales = [45000, 52000, 48000, 61000, 58000, 67000]Task: Create a professional line plot with:
- A green solid line (green = growth)
- Title: “Monthly Sales Performance (H1 2024)”
- X-axis label: “Month”
- Y-axis label: “Sales ($)”
- No scientific notation
# Your code hereSolution
import matplotlib.pyplot as plt
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
sales = [45000, 52000, 48000, 61000, 58000, 67000]
plt.plot(months, sales, color='green')
plt.ticklabel_format(axis='y', style='plain')
plt.title('Monthly Sales Performance (H1 2024)')
plt.xlabel('Month')
plt.ylabel('Sales ($)')
plt.show()Exercise 2: Temperature Forecast
A weather forecast shows expected temperatures for the next week:
days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
temps = [72, 75, 73, 68, 65, 67, 71]Task: Create a line plot with:
- Orange dashed line with circular markers
- Title: “7-Day Temperature Forecast”
- X-axis label: “Day of Week”
- Y-axis label: “Temperature (°F)”
Hint: Use linestyle='--' and marker='o'
# Your code hereSolution
import matplotlib.pyplot as plt
days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
temps = [72, 75, 73, 68, 65, 67, 71]
plt.plot(days, temps,
color='orange',
linestyle='--',
marker='o')
plt.title('7-Day Temperature Forecast')
plt.xlabel('Day of Week')
plt.ylabel('Temperature (°F)')
plt.show()Exercise 3: Multiple Customizations
Website traffic data for the past 6 months:
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
visitors = [125000, 142000, 138000, 156000, 171000, 189000]Task: Create your most professional plot yet with:
- Blue solid line with star markers
- Line width of 2
- Title: “Website Traffic Growth”
- Proper axis labels with units
- No scientific notation
Challenge: Try different combinations to see what looks best!
# Your code hereSolution
import matplotlib.pyplot as plt
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
visitors = [125000, 142000, 138000, 156000, 171000, 189000]
plt.plot(months, visitors,
color='blue',
marker='*',
linewidth=2)
plt.ticklabel_format(axis='y', style='plain')
plt.title('Website Traffic Growth')
plt.xlabel('Month')
plt.ylabel('Unique Visitors')
plt.show()Summary
You now create professional, customized visualizations. Let’s review the key concepts.
Key Concepts
Remove Scientific Notation
- Use
plt.ticklabel_format(axis='y', style='plain') - Makes large numbers readable
- Apply to
'x','y', or'both'axes
Always Add Labels
plt.title()for the graph titleplt.xlabel()for x-axisplt.ylabel()for y-axis (include units!)- Makes graphs self-explanatory
Customize Appearance
color=- Change line colorlinestyle=- Solid, dashed, dottedmarker=- Add markers at data pointslinewidth=- Adjust line thickness
Professional Graphs
- Need titles, labels, and readable numbers
- Use color meaningfully
- Choose appropriate markers
- Adjust line width for emphasis
Customization Reference
# Full customization example
plt.plot(x, y,
color='green', # Line color
linestyle='--', # Dashed line
marker='o', # Circular markers
linewidth=2) # Thicker line
plt.title('Your Title Here')
plt.xlabel('X-Axis Label')
plt.ylabel('Y-Axis Label (units)')
plt.ticklabel_format(axis='y', style='plain')
plt.show()Important Reminders
- Self-explanatory graphs: Anyone should understand without asking
- Use units: Always include units in axis labels
- Color with purpose: Colors should enhance meaning
- Less is more: Do not over-customize—clarity over decoration
Next Steps
You can create professional single-line plots. In the next lesson, you will learn to plot multiple lines on the same graph, add legends, and work with real-world time series data from CSV files.
Continue to Lesson 4 - Multiple Lines and Series
Plot multiple datasets on one graph for comparison and analysis
Back to Lesson 2 - Introduction to Matplotlib
Review creating basic line plots
Create Publication-Quality Visualizations
A graph should be self-explanatory. With titles, labels, and styling, your visualizations now communicate insights professionally.
Use customization to make your data speak clearly!