目录
问题出现
应用Matplotlib绘制图像,给点设置x和y坐标数据时,居然出现这样的错误:
MatplotlibDeprecationWarning: Setting data with a non sequence type is deprecated since 3.7 and will be remove two minor releases later
point.set_data(x, y)
提示方法过时,需要传入一个序列类型。
找到对应的代码,发现这一段确实可能传入标量:
def func(data):
x, y, Rt = data
time_text.set_text(r'$\theta$ = %.2f $\pi$' % (Rt/np.pi))
xx.append(x)
yy.append(y)
cx, cy = circle(Rt, R, R)
cycloid.set_data(xx, yy)
line.set_data((x,Rt), (y,R))
circle_line.set_data(cx, cy)
point.set_data(x, y)
问题解决
上述代码中,cycloid、line和circle_line传入的均为数组,x和y可能是个标量,因此,我们应该按照警告提示修改为[x],和[y],至此,该警告提示消失。代码如下:
point.set_data([x], [y])