Question:

In Python which function of matplotlib library is used to save a plot ?

Show Hint

Use plt.savefig("filename.png") after plotting, before plt.show(), to ensure the plot is saved properly.
Updated On: Jul 14, 2025
  • save()
  • saveplot()
  • export()
  • savefig()
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is D

Solution and Explanation

The matplotlib library is widely used in Python for creating static, animated, and interactive visualizations.
After creating a plot using matplotlib.pyplot, you often want to save it as an image file (e.g., PNG, PDF, SVG).
To do this, matplotlib provides the function savefig().
Here’s how it works:
import matplotlib.pyplot as plt

plt.plot([1, 2, 3], [4, 5, 6])
plt.title("Example Plot")
plt.savefig("plot.png")

This saves the current figure as a file named plot.png in the working directory.
Other options like save(), saveplot(), or export() do not exist in matplotlib.
Therefore, the correct answer is savefig().
Was this answer helpful?
0
0

Top Questions on Programming in Python

View More Questions

Questions Asked in CBSE CLASS XII exam

View More Questions