Closed
Description
Bug report
matplotlib glitch when rotating interactively a 3d animation
Plotting a 3d animation, matplotlib glitches when rotating interactively, despite doing it well when zooming. Setting a callback to stop animation during rotation doesn't seem to help, since (see code and attached video) the little red ball, which should be following the blue line, goes "off-track"
Using matplotlib 3.1.2
Code for reproduction
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.animation import FuncAnimation
t = np.linspace(0, 20*np.pi, 1000)
x = t
y = np.cos(t)
z = np.sin(t)
def animate(i, *fargs):
x, y, z = fargs[0:3]
ln = fargs[3]
# Plot small ball at time t[i]
ln.set_data_3d([x[i]], [y[i]], [z[i]])
ln.set_color('r')
ln.set_marker('.')
ln.set_markersize(10)
return ln,
fig = plt.figure(figsize=(9,7))
ax = plt.axes(projection='3d')
fix_ln = ax.plot(x, y, z, 'b-')[0]
ln = ax.plot([], [], [])[0]
ani = FuncAnimation(fig, animate, frames=np.arange(t.size), repeat=False, fargs=(x, y, z, ln), interval=0, blit=True)
# Comment the two following lines to play animation without callbacks:
plt.connect('button_press_event', lambda event: ani.event_source.stop())
plt.connect('button_release_event', lambda event: ani.event_source.start())
plt.show()
Matplotlib version
- Operating system: Ubuntu 19.10 eoan, Linux 5.3.0-24-generic #26-Ubuntu SMP Thu Nov 14 01:33:18 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
- Matplotlib version: 3.1.2 (installed with pip)
- Matplotlib backend (
print(matplotlib.get_backend())
): Qt5Agg - Python version: 3.7.3
- IPython version: 7.8.0
- Other libraries: numpy 1.17.2