---
title: "Interactive plots in Jupyter Notebook"
description: "How to create a plot that supports zooming"
author: "Bartosz Mikulski"
author_bio: "Principal AI Engineer & MLOps Architect. I bridge the gap between \"it works in a notebook\" and \"it works for 200 million users.\""
author_url: https://mikulskibartosz.name
author_linkedin: https://www.linkedin.com/in/mikulskibartosz/
author_github: https://github.com/mikulskibartosz
canonical_url: https://mikulskibartosz.name/interactive-plots-in-jupyter-notebook
---

You can draw an interactive plot in Jupyter Notebook (with matplotlib) if you run this code before drawing the plot:

```
%matplotlib notebook
```

The interactive plot looks like this and supports zooming:

![An interactive plot with zooming support](/images/2018-08-24-interactive-plots-in-jupyter-notebook/figure_1.png)

Note that you must run this line before every interactive plot you want to create. Also, the plot remains interactive until you call “%matplotlib notebook” again, change the mode to inline (“%matplotlib inline”) or quit the interactive mode by clicking the button in the top right corner of the plot.

If you draw a second plot while one of you plots is interactive the command will add another dataset to the existing plot instead of creating a new one:

![A second interactive plot](/images/2018-08-24-interactive-plots-in-jupyter-notebook/figure_2.png)