Q.In Python which function of matplotlib library is used to save a plot? (A) save() (B) saveplot() (C) export() (D) savefig()
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →The savefig() function in matplotlib saves a plot to a file; it's the standard method for exporting visualizations.
When you've spent time crafting a beautiful plot in Python—whether it's a line graph tracking temperature changes, a bar chart comparing sales figures, or a scatter plot revealing correlations—you naturally want to preserve that work. Matplotlib, the foundational plotting library in Python, provides a dedicated function for exactly this purpose: saving your figure to disk.
The function you need is savefig(). This method belongs to the pyplot module (commonly imported as plt) and writes the current figure to a file. The name itself is intuitive: "save figure." You call it after you've created your plot but before you close the figure or move on to other work.
Here's how it fits into a typical workflow. You build your plot with commands like plt.plot(), plt.bar(), or plt.scatter(), add labels and titles, adjust formatting, and then—when everything looks right—you invoke plt.savefig('filename.png'). The function handles the rest, writing your visualization to the specified file. It supports multiple formats: PNG for web use, PDF for documents, SVG for scalable graphics, and JPEG among others. You simply change the file extension, and matplotlib adapts.
The savefig() function must be called before plt.show() in your script. Once show() displays the plot interactively, the figure may be cleared, and saving afterward can produce a blank image. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.