3

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.

vestland
  • 55,229
  • 37
  • 187
  • 305
Dipan Ghosh
  • 176
  • 2
  • 9

2 Answers2

3

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.

Jonathan Eunice
  • 21,653
  • 6
  • 75
  • 77
0

Looks like you need to configure the SVG 'backend':

The matplotlib frontend or matplotlib API is the set of classes that do the heavy lifting, creating and managing figures, text, lines, plots and so on (Artist tutorial). This is an abstract interface that knows nothing about output. The backends are device-dependent drawing devices, aka renderers, that transform the frontend representation to hardcopy or a display device (What is a backend?). Example backends: PS creates PostScript® hardcopy, SVG creates Scalable Vector Graphics hardcopy,...

> # The default backend; one of GTK GTKAgg GTKCairo GTK3Agg GTK3Cairo
> # CocoaAgg MacOSX Qt4Agg Qt5Agg TkAgg WX WXAgg Agg Cairo GDK PS PDF SVG
> # Template.
> # You can also deploy your own backend outside of matplotlib by
> # referring to the module name (which must be in the PYTHONPATH) as
> # 'module://my_backend'. backend : qt4agg

Src: http://matplotlib.org/Matplotlib.pdf

rob2universe
  • 7,059
  • 39
  • 54