iPython Notebook svg Figures by Default

Konstantin Weitz

I just started using ipython, and I'm creating figures such as:

fig, axes = plt.subplots()
xs = range(0,100)
axes.plot(xs, [x*x for x in xs], 'r')

I know that the figures can be rendered as svgs, see here. Unfortunately, the figures are always rendered as a rasterized image. The rasterized images become very ugly when I'm using the notebook's zoom feature. Is there a way to change this behavior, such that figures are displayed as svg by default?

DaveP

You can change the default figure format in the ipython profile configuration files. What I did was create a configuration profile especially for the notebook server, using:

ipython profile create nbserver

At the command line. This creates a whole bunch of files under ~/.ipython/profile_nbserver which have example lines for almost every setting you could want to change (it might be somewhere such as ~/.config/ipython instead depending on your OS, not sure about where it would be under windows). You need to look in the file ipython_notebook_config.py. You should then add the the line:

c.InlineBackend.figure_formats = ['svg']

Note that this only applied to IPython 3.x, and that you can also specify additional formats as per @HarrySchreiner's comment. For IPython 2.x, you should set c.InlineBackEnd.figure_format='svg'. To use this profile you should start the notebook with

ipython notebook --profile=nbserver

If this is too much trouble then don't give a profile name when running create, and modify the default profile instead.

Also, you may want to have the line

c.IPKernelApp.matplotlib = 'inline'

so that each notebook will automatically start with the matplotlib inline backend used.

Originally I also wanted to use the svg backend instead of png to enable zooming etc. However, I found that certain plots, such as pcolor with a large number of points can just kill my browser when using the svg backend. So I find it easier to use png, and just use the xlim and ylim commands to zoom in manually if I need to.

Also, you should definitely tweak the line c.InlineBackend.rc to set more reasonable defaults for the figure size and the fonts used.

edit

Current recommended best practice is not to use pylab, but to explicitly import matplotlib and numpy instead, so I modified my answer to stop encouraging this. See this post for the reasons why:

http://carreau.github.io/posts/10-No-PyLab-Thanks.html

Also, if svg rendering is too slow for particular plot elements (such as pcolor or plot_surface), you can pass the option rasterized=True to these plot commands. This means that those particular parts of the plot will have fast pixel based rendering, but all the other plot elements will be nicely vectorized.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to set the matplotlib figure default size in ipython notebook?

From Dev

How to display line numbers in IPython Notebook code cell by default

From Dev

ipython notebook: how to toggle header invisible by default

From Dev

Including a notebook in another notebook in IPython?

From Dev

How to make new cells in ipython notebook markdown by default?

From Dev

iPython notebook plantuml extension

From Dev

ipython-notebook: print rmagic plots as svg

From Dev

How to change default colour scheme for ipython notebook?

From Dev

Where are python logs default stored when ran through IPython notebook?

From Dev

Interactive matplotlib/ipython figures on Windows

From Dev

How to display a table followed by a figure in succession in IPython notebook without repeated figures at the end?

From Dev

Default notebook directory in iPython Notebook - iPython 3.0.0

From Dev

IPython Notebook: How to combine HTML output and matplotlib figures?

From Dev

IPython/Jupyter notebook 3 - hide headers by default

From Dev

Ipython notebook caching issue

From Dev

Open 'ipython notebook' as: IPython notebook vs Jupyter

From Dev

Is it possible to speed up interactive IPython Notebook plots by not generating new figures every time?

From Dev

Display SVG in IPython notebook from a function

From Dev

Changing the default port for iPython notebook server / Jupyter

From Dev

Ipython Notebook: Default Initialization Python Code

From Dev

Default template for iPython notebook (using Jupyter)

From Dev

How to change the default browser used by the ipython/jupyter notebook in Linux?

From Dev

Ipython notebook link to external notebook

From Dev

ipython notebook .png figures after nbconvert not loaded by latest chrome/firefox

From Dev

ipython-notebook: print rmagic plots as svg

From Dev

Interactive matplotlib/ipython figures on Windows

From Dev

IPython Notebook - saving notebook fails

From Dev

Ipython notebook link to external notebook

From Dev

Ipython notebook - Create a new notebook (Python conda or default Python)

Related Related

  1. 1

    How to set the matplotlib figure default size in ipython notebook?

  2. 2

    How to display line numbers in IPython Notebook code cell by default

  3. 3

    ipython notebook: how to toggle header invisible by default

  4. 4

    Including a notebook in another notebook in IPython?

  5. 5

    How to make new cells in ipython notebook markdown by default?

  6. 6

    iPython notebook plantuml extension

  7. 7

    ipython-notebook: print rmagic plots as svg

  8. 8

    How to change default colour scheme for ipython notebook?

  9. 9

    Where are python logs default stored when ran through IPython notebook?

  10. 10

    Interactive matplotlib/ipython figures on Windows

  11. 11

    How to display a table followed by a figure in succession in IPython notebook without repeated figures at the end?

  12. 12

    Default notebook directory in iPython Notebook - iPython 3.0.0

  13. 13

    IPython Notebook: How to combine HTML output and matplotlib figures?

  14. 14

    IPython/Jupyter notebook 3 - hide headers by default

  15. 15

    Ipython notebook caching issue

  16. 16

    Open 'ipython notebook' as: IPython notebook vs Jupyter

  17. 17

    Is it possible to speed up interactive IPython Notebook plots by not generating new figures every time?

  18. 18

    Display SVG in IPython notebook from a function

  19. 19

    Changing the default port for iPython notebook server / Jupyter

  20. 20

    Ipython Notebook: Default Initialization Python Code

  21. 21

    Default template for iPython notebook (using Jupyter)

  22. 22

    How to change the default browser used by the ipython/jupyter notebook in Linux?

  23. 23

    Ipython notebook link to external notebook

  24. 24

    ipython notebook .png figures after nbconvert not loaded by latest chrome/firefox

  25. 25

    ipython-notebook: print rmagic plots as svg

  26. 26

    Interactive matplotlib/ipython figures on Windows

  27. 27

    IPython Notebook - saving notebook fails

  28. 28

    Ipython notebook link to external notebook

  29. 29

    Ipython notebook - Create a new notebook (Python conda or default Python)

HotTag

Archive