To save a plot as an image in pylab

Asked 2 years ago, Updated 2 years ago, 85 views

I want to save the image instead of showing it at the end of the code below. I'm saving the screenshot now Please tell me how to save it

from pylab import figure, axes, pie, title, show

# # Make a square figure and axes
figure(1, figsize=(6, 6))
ax = axes([0.1, 0.1, 0.8, 0.8])

labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15, 30, 45, 10]

explode = (0, 0.05, 0, 0)
pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)
title('Raining Hogs and Dogs', bbox={'facecolor': '0.8', 'pad': 5})

Show() # I don't want to show but I want to save it

python matplotlib

2022-09-22 22:28

1 Answers

To save the image, matplotlib.You must write pyplot.savefig (*args, **kwargs).

from pilot import figure, axes, pie, title, savefig #savefig
...
savefig('mypic.png')
savefig('mypic.pdf')

You can write with .


2022-09-22 22:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.