Ask Your Question
0

matplotlib Animation in Jupyter notebook

asked 2020-03-09 01:36:46 -0600

ortollj gravatar image

updated 2020-03-09 06:49:55 -0600

Hi

SageMath 9.0 , Ubuntu 18.04.4 LTS

matplotlib Animation little example

Why does this code work well in a Sage terminal window, but does not work in a Jupyter notebook window or on the SageCell server?

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

x_data = []
y_data = []

fig, ax = plt.subplots()
ax.set_xlim(0, 105)
ax.set_ylim(0, 12)
line, = ax.plot(0, 0)

def animation_frame(i):
    x_data.append(i * 10)
    y_data.append(i)

    line.set_xdata(x_data)
    line.set_ydata(y_data)
    return line, 

animation = FuncAnimation(fig, func=animation_frame, frames=np.arange(0, 10, 0.1), interval=10)
plt.show()
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-03-14 12:45:39 -0600

ortollj gravatar image

Oops!

If I had visited the Jupyter site earlier, I would have had my answer quickly!, it was enough to put at the head of the cell:

%matplotlib notebook

answer here on Jupyter forum

sorry

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-03-09 01:36:46 -0600

Seen: 411 times

Last updated: Mar 14