plt.savefig

Do you want to know the details regarding “plt.savefig”. If yes, you’re in the correct tutorial.

plt.savefig

plt.savefig('image.png')
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

plt.plot([1,2,3])
plt.savefig('/tmp/test.png')
import matplotlib.pyplot as plt
  
# creating plotting data
xaxis, yaxis =[1, 4, 9, 16, 25, 36, 49, 64, 81, 100], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  
# plotting 
plt.plot(xaxis, yaxis)
  
# saving the file.Make sure you 
# use savefig() before show().
plt.savefig("squares.png")
  
plt.show()
import matplotlib.pyplot as plt
plt.figure()
plt.plot([1,2,3],[1,2,3])
plt.savefig("out.png")

Final Thoughts

I hope this post helps you to know about “plt.savefig”. If you have any queries regarding this post please let us know via the comment section. Share this article with your friends and family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment