It seems the Qt backend cannot be used in Jupyter to animate a plot. Is that true in general?
The code shown below runs fine using the Qt4Agg or TkAgg backend in a script. It also runs fine using the notebook backend (%matplotlib notebook) or the tk backend (%matplotlib tk) in a Jupyter notebook.
However, when using %matplotlib qt (or %matplotlib qt4) in Jupyter, the window freezes and the Kernel dies.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation
y = np.cumsum(np.random.normal(size=30))
fig, ax = plt.subplots()
line, = ax.plot(np.arange(len(y)),y)
ax.set_xlim(0,30)
ax.set_ylim(y.min(),y.max())
def update(i):
x = np.arange(i)
line.set_data(x,y[:i])
ani = matplotlib.animation.FuncAnimation(fig, update, frames=30, repeat=False)
plt.show()
Commenting out the line ani = matplotlib.animation.FuncAnimation(...), the window appears and stays responsive also for %matplotlib qt backend in use. So it seems %matplotlib qt will not work with animations in Jupyter.
I'm using python 2.7, matplotlib 2.0, notebook server 4.4.1.
My question is:
- Is this behaviour expected?
- Can someone reproduce this?
- Does the Qt backend really not work in Jupyter with matplotlib animations?
- And if so, does anyone know the reason for this?