How to Save MatplotLib figures to image files


Matplotlib library is used to present data statistics in the best of manner with python as a base programming language. Data is been skeptically skewed to extract the most important information out of it and then presented using various functions of matplotlibs. These plots can then be used for reporting purpose. Hence, there is a constant requirement to exporting these data out from the python environment.

A very basic solution of the issue in concern, is to save the output of the matplotlib into image files, using a base code as below:

fig = plt.figure() ax = fig.add_axes([0,0,1,1]) ax.axis('equal') data_oneyear_emission = [87.75399456, 28.73753448, 2.500908237, 33.64595918, 24.68887142, 19.91823327] ax.pie(data_oneyear_emission, labels = ["nh3", "nox", "so2", "voc", "pm10", "pm25"],autopct='%1.2f%%') fig.savefig("output.png")

Getting any Errors while coding? Ask us on our new Forum:

Liked Article? Please Buy Author a Coffee


For Sponsored Advertisement OR Freelance Programming Article Submission, Contact us at
Recommended Deal Ends in

Online Games
Play 2048 Game Online and Relax.
Play 2048 Game Online

Why does everyone hate Java?
How much JavaScript to learn for Web Development
How to Convert EPOCH to Date in Java
Search Tags