r/IPython • • Jan 01 '16

How to have dynamically updating plot in IPython notebook?

I have code which dynamically generates new data points as time progresses. It takes for computing those data points and I would like to refresh the matplotlib plot dynamically in ipython notebook.. Following code best describes my attempt is achieving this functionality. The repository contains all necessary classes need for proper functioning.

Furthermore I'd appreciate general advice how to better make my visualizations, since matplotlib looks awkward in this example. Legend is placed over the plot and I'm unable to make plot larger.

7 Upvotes

8 comments sorted by

1

u/Thors_Son Jan 01 '16

You need to use %matplotlib qt to create the external window, since I do not believe dynamic plot updating is supported inline.

The basic idea is to grab the axis object, then only remove the most recent "line" object, and make the system wait (otherwise it will be too fast to see the update) and then draw the new line, iterating.

There's an implementation in this repo with an included example notebook.

For good looks, I would Google "Seaborn", and then just import that for starters. Other than that, find a type of plot you need, and search for answers on how to make specific components you need for that. It takes forever but with practice you can make some pretty fantastic looking plots.

3

u/hharison Jan 01 '16

Dynamic plot updating is supported in the notebook with the new %matplotlib nbagg backend.

4

u/luceth_ Jan 01 '16

For more recent versions of Jupyter and matplotlib (>= 1.5), this is aliased as %matplotlib notebook.

1

u/hharison Jan 01 '16

Good to know

1

u/Thors_Son Jan 01 '16

That's awesome to hear!

1

u/waspbr Jan 06 '16

Is there a way to draw the graphs in a separate window?

2

u/luceth_ Jan 28 '16

Sorry, I reddit poorly and didn't realize I had replies. YES -- you can use %matplotlib qt to get the usual matplotlib window.

1

u/waspbr Jan 28 '16

better late than never.

Cheers.