Closed
Description
Documentation Link
https://matplotlib.org/stable/gallery/animation/frame_grabbing_sgskip.html
Problem
An API part that used to accept scalars now expects a sequence.
Running:
import numpy as np
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from matplotlib.animation import FFMpegWriter
# Fixing random state for reproducibility
np.random.seed(19680801)
metadata = dict(title='Movie Test', artist='Matplotlib',
comment='Movie support!')
writer = FFMpegWriter(fps=15, metadata=metadata)
fig = plt.figure()
l, = plt.plot([], [], 'k-o')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
x0, y0 = 0, 0
with writer.saving(fig, "writer_test.mp4", 100):
for i in range(100):
x0 += 0.1 * np.random.randn()
y0 += 0.1 * np.random.randn()
l.set_data(x0, y0)
writer.grab_frame()
from https://matplotlib.org/stable/gallery/animation/frame_grabbing_sgskip.html
Used to work, but now it produces:
RuntimeError Traceback (most recent call last)
Cell In[1], line 30
28 x0 += 0.1 * np.random.randn()
29 y0 += 0.1 * np.random.randn()
---> 30 l.set_data(x0, y0)
31 writer.grab_frame()
File ~/miniconda3/envs/pytorch/lib/python3.12/site-packages/matplotlib/lines.py:665, in Line2D.set_data(self, *args)
662 else:
663 x, y = args
--> 665 self.set_xdata(x)
666 self.set_ydata(y)
File ~/miniconda3/envs/pytorch/lib/python3.12/site-packages/matplotlib/lines.py:1289, in Line2D.set_xdata(self, x)
1276 """
1277 Set the data array for x.
1278
(...)
1286 set_ydata
1287 """
1288 if not np.iterable(x):
-> 1289 raise RuntimeError('x must be a sequence')
1290 self._xorig = copy.copy(x)
1291 self._invalidx = True
RuntimeError: x must be a sequence
Which was not a problem in some previous versions.
Suggested improvement
- We should update the docs with an example illustrating how people should use the new implementation of
FFMpegWriter
.