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 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 notebook .png figures after nbconvert not loaded by latest chrome/firefox

From Dev

ipython-notebook: print rmagic plots as svg

From Dev

Display SVG in IPython notebook from a function

From Dev

ipython-notebook: print rmagic plots as svg

From Dev

Default template for iPython notebook (using Jupyter)

From Dev

How to change default colour scheme for ipython notebook?

From Dev

Ipython Notebook: Default Initialization Python Code

From Dev

ipython notebook: how to toggle header invisible by default

From Dev

Changing the default port for iPython notebook server / Jupyter

From Dev

IPython/Jupyter notebook 3 - hide headers by default

From Dev

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

From Dev

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

From Dev

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

From Dev

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

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

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

From Dev

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

From Dev

Interactive matplotlib/ipython figures on Windows

From Dev

Interactive matplotlib/ipython figures on Windows

From Dev

Open 'ipython notebook' as: IPython notebook vs Jupyter

From Dev

Ipython notebook link to external notebook

From Dev

Including a notebook in another notebook in IPython?

From Dev

IPython Notebook - saving notebook fails

From Dev

Ipython notebook link to external notebook

From Dev

Ipython notebook caching issue

From Dev

iPython notebook plantuml extension

Related Related

  1. 1

    Default notebook directory in iPython Notebook - iPython 3.0.0

  2. 2

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

  3. 3

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

  4. 4

    ipython-notebook: print rmagic plots as svg

  5. 5

    Display SVG in IPython notebook from a function

  6. 6

    ipython-notebook: print rmagic plots as svg

  7. 7

    Default template for iPython notebook (using Jupyter)

  8. 8

    How to change default colour scheme for ipython notebook?

  9. 9

    Ipython Notebook: Default Initialization Python Code

  10. 10

    ipython notebook: how to toggle header invisible by default

  11. 11

    Changing the default port for iPython notebook server / Jupyter

  12. 12

    IPython/Jupyter notebook 3 - hide headers by default

  13. 13

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

  14. 14

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

  15. 15

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

  16. 16

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

  17. 17

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

  18. 18

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

  19. 19

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

  20. 20

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

  21. 21

    Interactive matplotlib/ipython figures on Windows

  22. 22

    Interactive matplotlib/ipython figures on Windows

  23. 23

    Open 'ipython notebook' as: IPython notebook vs Jupyter

  24. 24

    Ipython notebook link to external notebook

  25. 25

    Including a notebook in another notebook in IPython?

  26. 26

    IPython Notebook - saving notebook fails

  27. 27

    Ipython notebook link to external notebook

  28. 28

    Ipython notebook caching issue

  29. 29

    iPython notebook plantuml extension

HotTag

Archive