python报错:ValueError: not enough image data和IndexError: list index out of range

python代码在电脑上能跑,在开发板上会报这个错误,库我已经安好,这可能是什么原因,怎么修改?保存有问题吗?

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/matplotlib/animation.py", line 230, in saving
    yield self
  File "/usr/lib/python3/dist-packages/matplotlib/animation.py", line 1174, in save
    writer.grab_frame(**savefig_kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/animation.py", line 578, in grab_frame
    buf.getvalue()))
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2412, in frombytes
    im.frombytes(data, decoder_name, args)
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 815, in frombytes
    raise ValueError("not enough image data")
ValueError: not enough image data

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "22.py", line 25, in <module>
    ani.save('output.gif', fps=30, savefig_kwargs={'dpi': 80}, writer='pillow')
  File "/usr/lib/python3/dist-packages/matplotlib/animation.py", line 1174, in save
    writer.grab_frame(**savefig_kwargs)
  File "/usr/lib/python3.7/contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/lib/python3/dist-packages/matplotlib/animation.py", line 232, in saving
    self.finish()
  File "/usr/lib/python3/dist-packages/matplotlib/animation.py", line 581, in finish
    self._frames[0].save(
IndexError: list index out of range

源代码:

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

# 数据处理
x = np.loadtxt('x.txt')
y = np.loadtxt('y.txt')
# 50000组数据,位为适应开发板已降频

# 降采样
num_samples = 500  # 设置采样点数量
idx = np.linspace(0, len(x) - 1, num_samples).astype(int)
x_sampled, y_sampled = x[idx], y[idx]

# 初始化画布和轴
fig, ax = plt.subplots()
line, = ax.plot([], [], 'r')
ax.set_xlim(-6, 3)
ax.set_ylim(1, 10)

# 动画更新函数
def update(num):
    line.set_data(x_sampled[:num], y_sampled[:num]) # 每次更新显示一个数据点
    return line,

# 动画播放
ani = animation.FuncAnimation(fig, update, frames=len(x_sampled), interval=20, blit=True)

# 保存动画文件
ani.save('output.gif', fps=30, savefig_kwargs={'dpi': 80}, writer='pillow')


数据文件是什么样的呢?

x = np.loadtxt('x.txt')
y = np.loadtxt('y.txt')