Thanks to theidioms.com









Matplotlib Transparent Background – How to save a transparent plot

Matplotlib Transparent Background
Data Science

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)
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 plot Matplotlib Transparent Background - How to save a transparent plot

Leave your thought here

Your email address will not be published. Required fields are marked *