Skip to content

Dear Internet Explorer user: Your browser is no longer supported

Please switch to a modern browser such as Microsoft Edge, Mozilla Firefox or Google Chrome to view this website's content.

Larger matplotlib images in Jupyter Notebook

Simple code to enable matplotlib to generate larger inline images in Jupyter Notebook.

When using Jupyter Notebook to write scripts in Python, the default matplotlib image size is very small. This may be a problem when writing code that will be used to analyse images.

One way to work around this is to change the header from %matplotlib inline to %matplotlib notebook. This will produce a larger plot, but not one that will be displayed inline directly below the code cell that produced it.

Screen capture from Jupyter Notebook showing an inline image
Jupyter Notebook output showing a matplotlib image when %matplotlib notebook is used.

A better way is to use the rcParams parameter as follows:

%matplotlib notebook
import matplotlib as mpl
mpl.rcParams['figure.figsize'] = [12, 12]
mpl.rcParams['figure.dpi'] = 72

Unfortunately the unit of measure for figure.figsize is inches. The output will be larger but remain inline:

In Jupyter Notebook, you may need to place the last two lines in a separate cell for the changes to take effect, but the result will be larger inline images.

   

Comments

No comments have yet been submitted. Be the first!

Have Your Say

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.