Search code examples
pythonsvgmatplotlib-venn

Export SVG out of matplotlib-venn


I have started to use matplotlib-venn for plotting venn diagram. It's a very useful tool, but I would like to know whether the graph generated can be saved in an SVG (or even pdf) format. I want to keep the graph vector, not rasterize it as in png.

I think there is a way, so if you can point me to it, that would be very helpful.


Solution

  • You can use the standard savefig method. Just give your output path a '.svg' extension:

    from matplotlib_venn import venn2
    import matplotlib.pyplot as plt
    
    venn2(subsets = (3, 2, 1))
    plt.savefig('venn2.svg')
    

    You can save to PNG with a .png extension and... you can probably see where this is going for other formats.