Question:medium

How can you save a matplotlib plot as a file?

Show Hint

You can specify the format when saving a figure using \texttt{plt.savefig('filename.png')}. If no format is specified, matplotlib will infer it from the file extension.
Updated On: Feb 16, 2026
  • plt.export()
  • plt.save()
  • plt.savefig()
  • plt.store()
Show Solution

The Correct Option is C

Solution and Explanation

Step 1: Understanding the task.
To save a matplotlib plot to a file, the `savefig()` function is utilized. This function stores the current figure in a specified format (e.g., PNG, PDF, SVG).
Step 2: Evaluate each option.
- Option (1) plt.export(): Matplotlib does not have a `export` function for saving figures. - Option (2) plt.save(): This is not a valid matplotlib function. - Option (3) plt.savefig(): This is the correct function for saving the plot to a specified file. - Option (4) plt.store(): This is not a valid matplotlib function.
Step 3: Conclusion.
The `savefig()` function is the correct method for saving a matplotlib plot as a file.
Final Answer: \[\boxed{\text{Use plt.savefig() to save a plot as a file in matplotlib.}}\]
Was this answer helpful?
0