pythonmatplotlibmatplotlib-venn

How to save VennDiagram as .png file in matplotlib_venn


I would like to save a venn diagram as a .png (or some other file) to insert into a document. I am using matplotlib_venn.

Following the solution here:

How to save VennDiagram as PNG figure in matplotlib_venn

I just get an empty (white) .png file as follows:

enter image description here

My code is:

from matplotlib_venn import venn2
from matplotlib import pyplot as plt

venn2(subsets=(5,8,4))
plt.savefig(path+'venn1A.png')

Solution

  • write plt.savefig(path+'venn1A.png') before plt.show() because plt.show() free memory space taken by graph so if you write plt.savefig(path+'venn1A.png') after plt.show() then you will got an empty(white) image.

    Note:-if you don't provide the .png extension then by default savefig() method saves images in png format

    FURTHER NOTE: ATOM IDE displays diagrams automatically (ie plt.show() is implicit). It is thus necessary to submit all lines of code together rather than each line individually.