Matplotlib Transparent Background - How to save a transparent plot

Table of Contents
Primary Item (H2)

To save a Matplotlib plot with transparent background, use the transparent=True parameter in Matplotlib's savefig() method.

Here is an example of how to save a Matplotlib plot with transparent background:

import matplotlib.pyplot as plt
import numpy as np

# Sample data points
x = np.linspace(0,6,31)
y = np.exp(-0.5*x) * np.sin(x)

# Plotting
plt.plot(x, y, 'bo-')

# Saving the figure with transparent background
plt.savefig('figure.png', transparent=True)
Matplotlib Transparent Background - How to save a plot with transparent background

This saved plot is now transparent.

Matplotlib Transparent Background - How to save a plot with transparent background (Transparency)

This solution has been sourced from the top-voted solution on 'How to export plots from Matplotlib with transparent background?'.


Matplotlib Transparent Background - How to save a transparent plotMatplotlib Transparent Background - How to save a transparent plot

Do you want to learn Python, Data Science, and Machine Learning while getting certified? Here are some best selling Datacamp courses that we recommend you enroll in:

  1. Introduction to Python (Free Course) - 1,000,000+ students already enrolled!
  2. Introduction to Data Science  in Python- 400,000+ students already enrolled!
  3. Introduction to TensorFlow for Deep Learning with Python - 90,000+ students already enrolled!
  4. Data Science and Machine Learning Bootcamp with R - 70,000+ students already enrolled!
Written by
The Click Reader
At The Click Reader, we are committed to empowering individuals with the tools and knowledge needed to excel in the ever-evolving field of data science. Our sole focus is delivering a world-class data science bootcamp that transforms beginners and upskillers into industry-ready professionals.

Interested In Data Science Bootcamp?
Request more info now.

Lead Collection Form
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram