2

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')
brb
  • 1,123
  • 17
  • 40
  • 1
    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 that then you will got an empty(white) image – Anurag Dabas Feb 20 '21 at 07:22
  • 1
    If you submit this as an answer I will mark as accepted. Otherwise, I can do it later. Thanks again. – brb Feb 20 '21 at 07:42

1 Answers1

2

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.

brb
  • 1,123
  • 17
  • 40
Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41