Question:

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: Sep 18, 2025
  • plt.export()
  • plt.save()
  • plt.savefig()
  • plt.store()
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: Understanding the task.
To save a plot as a file in matplotlib, the function \texttt{savefig()} is used. This function saves the current figure to a specified file format (e.g., PNG, PDF, SVG, etc.).
Step 2: Evaluate each option.
- Option (1) plt.export(): There is no function named \texttt{export} in matplotlib for saving figures. - Option (2) plt.save(): This is not a valid function in matplotlib. - Option (3) plt.savefig(): This is the correct function to save the plot. It saves the current figure to the specified file. - Option (4) plt.store(): This is not a valid function in matplotlib.
Step 3: Conclusion.
The function \texttt{savefig()} is the correct way to save 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
0

Questions Asked in CUET exam

View More Questions