Ask Your Question
1

matplotlib Animation in Jupyter notebook

asked 2020-03-09 07:36:46 +0200

ortollj gravatar image

updated 2020-03-09 12:49:55 +0200

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
1

answered 2020-03-14 18:45:39 +0200

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

Comments

You can accept the answer to mark the question as solved.

slelievre gravatar imageslelievre ( 2020-12-31 10:31:45 +0200 )edit

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 07:36:46 +0200

Seen: 1,494 times

Last updated: Mar 14 '20