How to change the opacity of a plot using Matplotlib

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Changing the opacity of plot can be extremely useful when you want to compare multiple features, especially when your plot is crowded.

Here is a simple example of a line plot, using the matplotlib library.

import matplotlib.pyplot as plt
import pandas as pd

# We create our dataframe
df = pd.DataFrame(index=range(0,10), data={"col1" : range(0,10)})

fig, axes = plt.subplots(1,1, figsize=(8,6))

# We do a line plot on the axes
axes.plot(df.index,
          df["col1"],
          alpha=0.5) # see the alpha

# Fixing the layout to fit the size
fig.tight_layout()

# Showing the plot
plt.show()
How to change the opacity of a plot using the alpha parameter

As you can see we use the alpha parameter that specify the opacity of the plot which has as value [0,1] (e.g. 0.5).

Here you are ! you now know how to set the opacity of a plot using Matplotlib.

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Free Newsletter

Master Data Science in Days, Not Months 🚀

Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚

Weekly simple and practical lessons
Access to ready to use code examples
Skip the math, focus on results
Learn while drinking your coffee

By subscribing, you agree to receive our newsletter. You can unsubscribe at any time.