Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document a trick for dynamic plotting in Jupyter/iPython #1415

Closed
wangkuiyi opened this issue Feb 22, 2017 · 1 comment
Closed

Document a trick for dynamic plotting in Jupyter/iPython #1415

wangkuiyi opened this issue Feb 22, 2017 · 1 comment

Comments

@wangkuiyi
Copy link
Collaborator

We tried the following code snippet. It works with try.jupyter.org:

%matplotlib inline
import time
import pylab as pl
from IPython import display
for i in range(10):
    pl.plot(pl.randn(100))
    display.clear_output(wait=True)
    display.display(pl.gcf())
    pl.gcf().clear()
    time.sleep(1.0)

where pl.gcf().clear() clears existing plots.

Documents for users' review: https://ipython.org/ipython-doc/3/api/generated/IPython.display.html

@livc
Copy link
Member

livc commented Feb 22, 2017

I tried to write a code snippet on @wangkuiyi 's basis.
The effect is as follow:

2333

import numpy as np
import time
import pylab as pl
from IPython import display

def plot(x, y):
    pl.ylim(0, 10)
    pl.xlim(0, 10)
    
    pl.plot(x, y)
    pl.xlabel('X')
    pl.ylabel('Error')

    display.clear_output(wait=True)
    display.display(pl.gcf())
    pl.gcf().clear()
    time.sleep(1.0)
    
    
def train(callback):
    x = []
    y = []
    for i in range(11):
        x.append(i)
        y.append(np.random.rand()*10)
        callback(x, y)
        
    
train(plot)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants