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().