Working on a data visualization project for a retail company, I had to create weekly sales charts using Python. The client wanted the charts in PNG format so they could easily include them in PowerPoint presentations and reports.
If you’ve ever used Matplotlib in Python, you probably know how easy it is to display charts using plt.show(). But when it comes to saving those charts as a high-quality image file, especially as PNG, you need to use the right functions and parameters.
In this tutorial, I’ll show you multiple ways to save Matplotlib chart as PNG file in Python. I’ll walk you through each method step-by-step, share complete code examples, and explain some useful tips I’ve learned from over a decade of working with Python data visualization.
Save Charts as PNG in Python
Before I jump into the methods, let me quickly explain why PNG is such a popular format. PNG (Portable Network Graphics) is lossless, meaning it preserves image quality even after compression. This makes it perfect for charts and graphs, where clarity and precision are important.
When I need to share charts with clients or include them in reports, I always choose PNG because it looks sharp on both screens and printouts. Plus, it’s supported everywhere, from emails to dashboards.
Method 1 – Save Matplotlib Chart as PNG Using savefig()
The easiest and most common way to save a Matplotlib chart as a PNG in Python is by using the savefig() function. This function gives you full control over file format, resolution, and transparency.
Here’s how I typically do it in my projects.
import matplotlib.pyplot as plt
# Sample data: U.S. retail sales (in millions)
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
sales = [420, 380, 450, 500, 480, 530]
# Create a simple line chart
plt.figure(figsize=(8, 5))
plt.plot(months, sales, color='blue', marker='o', linewidth=2)
plt.title('Monthly Retail Sales in the U.S. (in Millions)', fontsize=14)
plt.xlabel('Month')
plt.ylabel('Sales')
plt.grid(True)
# Save the chart as a PNG file
plt.savefig('us_retail_sales.png', format='png', dpi=300, bbox_inches='tight')
# Display the chart
plt.show()You can refer to the screenshot below to see the output.

In this example, I used the savefig() function with a few important parameters. The dpi=300 ensures a high-resolution output suitable for printing, and bbox_inches=’tight’ trims any extra whitespace around the chart.
When you run this code, a PNG file named us_retail_sales.png will be saved in your current working directory.
Method 2 – Save Matplotlib Chart as PNG Using savefig() with Transparency
Sometimes, I need to save charts with transparent backgrounds, especially when I’m creating overlays for dashboards or web graphics. Matplotlib makes this easy with the transparent=True argument.
Here’s an example.
import matplotlib.pyplot as plt
# Data: Average temperature by month (U.S. cities)
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
temperature = [32, 35, 45, 55, 65, 75]
plt.figure(figsize=(8, 5))
plt.bar(months, temperature, color='orange')
plt.title('Average Monthly Temperature in the U.S.', fontsize=14)
plt.xlabel('Month')
plt.ylabel('Temperature (°F)')
# Save chart as PNG with transparent background
plt.savefig('us_temperature_chart.png', format='png', dpi=300, transparent=True)
plt.show()You can refer to the screenshot below to see the output.

This method is perfect when you want your chart to blend seamlessly with different backgrounds, such as PowerPoint slides or web pages.
Method 3 – Save Matplotlib Chart as PNG Without Displaying It
In many automation scripts, I don’t want the chart to pop up on the screen. Instead, I prefer to save it directly as a PNG file. This is useful when generating hundreds of charts automatically using Python.
Here’s how I do it.
import matplotlib.pyplot as plt
# Data: Online sales growth percentage
years = [2019, 2020, 2021, 2022, 2023]
growth = [5, 25, 18, 22, 15]
plt.plot(years, growth, marker='o', color='green')
plt.title('U.S. Online Sales Growth (%)')
plt.xlabel('Year')
plt.ylabel('Growth Percentage')
plt.grid(True)
# Save chart directly without showing
plt.savefig('us_online_sales_growth.png', dpi=300)
plt.close()Here, I used plt.close() to close the figure after saving it. This prevents the chart from displaying, which is ideal for batch processing or scheduled Python scripts.
Method 4 – Save Multiple Matplotlib Charts as PNGs in Python
If you’re working with multiple datasets, you might need to save several charts in one go. I often do this when analyzing sales data from different U.S. states or product categories.
Here’s how you can automate it.
import matplotlib.pyplot as plt
# State-wise sales data
data = {
'California': [400, 420, 450, 470, 490],
'Texas': [350, 370, 390, 410, 430],
'Florida': [300, 320, 340, 360, 380]
}
years = [2019, 2020, 2021, 2022, 2023]
# Loop through each state and save chart as PNG
for state, sales in data.items():
plt.figure(figsize=(7, 4))
plt.plot(years, sales, marker='o', linewidth=2)
plt.title(f'{state} Sales Trend (in Millions)')
plt.xlabel('Year')
plt.ylabel('Sales')
plt.grid(True)
filename = f'{state.lower()}_sales_trend.png'
plt.savefig(filename, dpi=300)
plt.close()This script will generate three PNG files, one for each state, with clean, high-quality charts. I use this approach often when preparing visual reports for clients.
Method 5 – Save Matplotlib Chart as PNG in a Specific Folder
Sometimes, I want to organize my charts neatly in a specific directory. Python’s os module makes this simple.
import matplotlib.pyplot as plt
import os
# Create a folder named 'charts' if it doesn't exist
output_folder = 'charts'
os.makedirs(output_folder, exist_ok=True)
# Data for demonstration
categories = ['Electronics', 'Clothing', 'Groceries', 'Home Decor']
sales = [1200, 900, 1500, 700]
plt.figure(figsize=(8, 5))
plt.bar(categories, sales, color='purple')
plt.title('Retail Category Sales in the U.S.')
plt.xlabel('Category')
plt.ylabel('Sales (in Thousands)')
# Save the chart inside the 'charts' folder
file_path = os.path.join(output_folder, 'category_sales.png')
plt.savefig(file_path, dpi=300)
plt.show()You can refer to the screenshot below to see the output.

This method helps keep your project organized, especially when dealing with multiple Python scripts or large datasets.
Tips for Saving High-Quality PNG Charts in Python
Over the years, I’ve learned a few best practices to ensure my charts always look professional and clear.
- Use dpi=300 or higher for print-quality images.
- Set bbox_inches=’tight’ to remove extra padding around the chart.
- Use vector formats (like SVG) when scalability is more important than file size.
- Avoid dark backgrounds unless your chart is meant for dark-mode dashboards.
- Always specify the file format explicitly using format=’png’ for clarity.
These small details can make a big difference when your charts are used in presentations or reports.
Common Mistakes When Saving Charts as PNG in Python
Even experienced Python developers sometimes make mistakes when saving charts. Here are a few I’ve seen (and made myself):
- Forgetting to call plt.savefig() before plt.show() — this can result in a blank image.
- Not specifying the correct file path — especially when running scripts from different directories.
- Using low dpi values, which make charts look blurry when printed.
- Forgetting to close figures in loops, which can consume unnecessary memory.
Avoiding these pitfalls will save you time and ensure your charts always come out looking great.
So that’s how I save Matplotlib charts as PNG files in Python. Whether you’re creating a quick visualization for a meeting or generating hundreds of charts for a data report, the savefig() function gives you all the flexibility you need.
I personally use these methods every day in my Python projects, especially when preparing visual analytics for U.S.-based clients. Once you get comfortable with savefig(), you’ll find it incredibly easy to create and export professional-quality charts.
You may also like to read:
- Save a Matplotlib Plot as a Transparent PNG in Python
- Save NumPy Array as PNG Image in Python Matplotlib
- Save a Matplotlib Plot as PNG Without Borders in Python
- How to Save a Matplotlib Axis as PNG in Python

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.