[Python] An iterative plot is not drawn in jupyter notebook while python works fine. Why?

Discussão em 'Python' iniciado por Stack, Novembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I have written an iterative plot code for python using plt.draw(). While it works fine for python interpreter and ipython also, but it does not work in jupyter notebook. I am running python in virtualenv in Debian. The codes are

    import matplotlib.pyplot as plt
    import numpy as np

    N=5
    x = np.arange(-3, 3, 0.01)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    for n in range(N):
    y = np.sin(np.pi*x*n)
    line, = ax.plot(x, y)
    plt.draw()
    plt.pause(0.5)
    line.remove()


    This works fine in command line such as


    $ python a.py
    ​

    But, in jupyter notebook, it plots first figure and then, repeat <Figure size ... 0 Axes> for N-1 times, not drawing the new figure inside axis. It looks the problem of jupyter, because no problem in running python code. How can I fix this? Or plotly would work in jupyter? (N.B. I happen to find a jupyter community site and posted there also.)

    [​IMG]

    Continue reading...

Compartilhe esta Página