# Matplotlib Transparent Background – How to save a transparent plot

August 8, 2021 2021-10-04 7:35## Matplotlib Transparent Background – How to save a transparent plot

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)

This saved plot is now transparent.

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

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

- 2022 Complete Python Bootcamp From Zero to Hero in Python - 1,000,000+ students already enrolled!
- Python for Data Science and Machine Learning Bootcamp - 400,000+ students already enrolled!
- Complete Guide to TensorFlow for Deep Learning with Python - 90,000+ students already enrolled!
- Data Science and Machine Learning Bootcamp with R - 70,000+ students already enrolled!
- The Complete SQL Bootcamp 2021: Go from Zero to Hero - 400,000+ students already enrolled!