How to resize graphics in IPython Notebook without loss of quality?

3

In IPython Notebook I produce graphics with (for example):

x = [1,2,3,4]
y = [5,6,7,8]
plot(x, y)

When I position the cursor on the generated graph, the tool to resize the graph appears in the lower right corner, but when I resize it it becomes "pixelated":

I can report figure(figsize=(12,8)) before plotting the chart but it does not seem to me the most efficient solution (needs to be specified before each chart). Is there any way to resize graphics on the Notebook interactively without loss of quality?

    
asked by anonymous 14.12.2013 / 22:49

1 answer

4

Instead of producing graphics in PNG (bitmap image format), you can configure IPython Notebook to produce graphics in SVG (vector format), which does not lose its definition.

You can change the default format of the graphics, add the following to the beginning of your notebook file (works from IPython 1.0):

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

Using SVG you will no longer have the chart resize tool, but you can use the zoom of your browser to see the chart more closely.

Standard size of the figures

If you prefer to continue using PNG, you set the default size for the figures:

%config InlineBackend.rc={'figure.figsize': (12, 8)}

or

import pylab
pylab.rcParams['figure.figsize'] = (8.0, 8.0)

Retina

Still using PNG, you can use the backend retina , which produces images with 4 times the resolution:

%config InlineBackend.figure_format='retina'

You can combine this solution with the previous one.

    
15.12.2013 / 12:18