Skip to content Skip to sidebar Skip to footer

Outputing Multiple .png Graphs In Matplotlib To One Zip File In Python 3.4

I wrote a program that outputs multiple different pie charts (more than 60) from a CSV file using MatPlotLib in Python. I don't think I need to share all of the code, but I have a

Solution 1:

Sure, there's the standard zipfile module, which can zip existing files, and it can also zip a string of bytes. So if you don't want to create the files separately and then zip them you could save them to BytesIO objects and then zip up those byte buffers. I've linked you to the Python 3 docs, but those features are also available in Python 2.

Solution 2:

If you want to save both png's and the zip, maybe for debugging purposes, you can do something like using zipfile:

import zipfile

zf = zipfile.ZipFile('myzip.zip', mode='w')

zf.write('image1.png')
zf.write('image2.png')
# ...

zf.close()

Post a Comment for "Outputing Multiple .png Graphs In Matplotlib To One Zip File In Python 3.4"