Question:easy

How can you save a matplotlib figure to a file?

Show Hint

The function is savefig, called as plt.savefig("file.png").
Updated On: Oct 1, 2026
  • plt.savefile()
  • plt.savefig(filename)
  • plt.storefig(filename)
  • plt.save(filename)
Show Solution

The Correct Option is B

Solution and Explanation

Step 1: Idea:
We use our memory of the pyplot function list and also check whether each name is real.

Step 2: Recall the function.
The pyplot function for saving is spelled s-a-v-e-f-i-g, short for save figure.

Step 3: Check the spelling of each option.
savefile, storefig and save are not names in the pyplot module, so each would give an error.

Step 4: Check the argument.
Option 2 passes a file name, as savefig needs. So it is the answer.

Step 5: Test every option against the result.
Option 1: There is no function with the name savefile, so this fails.
Option 2: savefig takes a file name and writes the figure, so it fits.
Option 3: There is no function with the name storefig, so this fails.
Option 4: There is no function with the name save in pyplot for figures, so this fails.

Step 6: Conclusion.
Option 2 is correct. \[ \boxed{\text{plt.savefig(filename)}} \]
Was this answer helpful?
0


Questions Asked in CUET (UG) exam