Course contentsShow
← Data Science
Lesson 1273 of 2,14532. Visualization with Matplotlib and SeabornFree lesson

Saving Figures: Formats and Resolution

Export plots to various file formats with appropriate DPI, size, and transparency for reports and presentations.

Saving Figures: Formats and Resolution

What you'll learn: How to export your Matplotlib visualizations in different file formats with the right quality settings for any purpose.

Why Export Settings Matter

You've created the perfect plot—now you need to save it for a report, presentation, or publication. Just like exporting a photo, the format and quality you choose determine how your visualization will look and how much disk space it takes. The wrong settings can make your chart blurry on a projector or create unnecessarily huge files.

File Formats: Choosing Wisely

Vector formats (like PDF, SVG, EPS) store mathematical descriptions of shapes. They scale perfectly to any size without losing quality—ideal for publications and professional reports.

Raster formats (like PNG, JPG) store pixels. They're resolution-dependent but universally compatible—great for presentations, web pages, and quick sharing.

DPI: Dots Per Inch

DPI controls resolution for raster formats. Think of it as pixel density:

  • 72-96 DPI: Screen viewing only
  • 150 DPI: Acceptable for most reports
  • 300 DPI: Print-quality standard
  • 600 DPI: High-end publications
fig.savefig('plot.png', dpi=300)  # High-quality PNG
fig.savefig('plot.pdf')            # Vector format (DPI irrelevant)

Additional Export Controls

Control size, transparency, and cropping:

fig.savefig('plot.png', 
            dpi=300,                    # Resolution
            bbox_inches='tight',        # Remove extra whitespace
            transparent=True,           # Transparent background
            facecolor='white')          # Or set background color

Key Takeaway: Choose vector formats (PDF, SVG) for scalable, professional outputs; use raster formats (PNG at 300 DPI) for presentations and web; always use bbox_inches='tight' to eliminate wasted space around your figures.