Skip to content
CampusEduX

Problem 3: Save a Figure to a File

Easypython
Learn the Concept: Matplotlib (Condensed Reference)

Problem Description

Write a Python program that creates a simple chart and saves it as a PNG file with a specified DPI, before displaying it.

Input

Simple chart data, a filename, and a DPI value.

Output

A saved image file, and the displayed chart.

Constraints

  • None specific.

Example Input

text
data=[1,2,3,4], filename="my_chart.png", dpi=200

Example Output

text
(A file "my_chart.png" is created, and the chart is also displayed)

Concepts Covered

plt.savefig(), dpi parameter, correct call order.

Related Problems

  • Problem 1: Create Two Subplots Side by Side
    Easy · python
    Solve Problem
  • Problem 2: Add Titles and a Figure-Wide Title
    Easy · python
    Solve Problem
  • Problem 4: Build a 2x2 Dashboard of Four Charts
    Easy · python
    Solve Problem

Input (stdin)

Output

Run your code to see output here...