1

Currently, I'm using the following at the start of my notebook to generate SVG plots:

%matplotlib inline
%config InlineBackend.figure_format = 'svg'

When using the nbagg backend instead (like this: %matplotlib nbagg), plots are generated as PNGs. Is it possible to configure the nbagg backend to generate SVGs?

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283

1 Answers1

2

The Agg backend in matplotlib uses the Anti-Grain Geometry 2D graphics library to generate bitmap graphics. The documentation for the backend states:

Output to RGBA and PNG, optionally JPEG and TIFF

The NbAgg backend wraps the Agg backend (via WebAgg core) and so is also limited to those output types.

Note that this simply defines the backend used to generate figures for viewing. Regardless of backend, you can still save figures to SVG format using figure.savefig('<filename'> format='svg') (or using a filename ending in .svg).

mfitzp
  • 15,275
  • 7
  • 50
  • 70
  • Thanks, that explains it. I'll have to try to tweak the dpi settings to get better quality. With default settings, svg looks much better than png. – Björn Pollex Jun 02 '16 at 14:52
  • @BjörnPollex you may be better keeping to screen resolution (~96dpi; default) and adjusting the figure size. Low quality of figures in the notebook is usually caused by browser scaling of the resulting image *after* it's been rendered. In Chrome (and probably others) if you right click and select "Open image in new tab" you can see the "real" image. – mfitzp Jun 03 '16 at 09:53