我试图设置一个动画来实时显示通过GPIB接口获取的一些数据。只要我使用线,也就是matplotlib的plot()函数,我就可以很好地工作。
然而,由于我正在获取离散数据点,所以我想使用scatter()函数。这导致了以下错误:“set_array()需要正好2个参数(给出3个)”
下面的代码中显示了错误在2个位置上的表现。
def intitalisation():
realtime_data.set_array([0],[0]) ******ERROR HERE*******
return realtime_data,
def update(current_x_data,new_xdata,current_y_data, new_ydata):#
current_x_data = numpy.append(current_x_data, new_xdata)
current_y_data = numpy.append(current_y_data, new_ydata)
realtime_data.set_array( current_x_data , current_y_data ) ******ERROR HERE*******
def animate(i,current_x_data,current_y_data):
update(current_x_data,new_time,current_y_data,averaged_voltage)
return realtime_data,
animation = animation.FuncAnimation(figure, animate, init_func=intitalisation, frames = number_of_measurements, interval=time_between_measurements*60*1000, blit=False, fargs= (current_x_data,current_y_data))
figure = matplotlib.pyplot.figure()
axes = matplotlib.pyplot.axes()
realtime_data = matplotlib.pyplot.scatter([],[])
matplotlib.pyplot.show()
那么我对大家的问题是,为什么set_array()认为我向它传递了3个参数?我不理解,因为我只看到有2个参数。
另外,我该如何纠正这个错误?
artist.set_offsets([[x0, x1, ...], [y0, y1, ...]])
。它将被转换为一个2D numpy数组。在你的示例代码中,可能是realtime_data.set_offsets([current_x_data , current_y_data])
。 - Joe Kingtonshape(offsets) = (4097, 2)
和shape(alpha) = (4097,)
,s.set_offsets(offsets)
看起来可以工作,但是在 makeMappingArray 中s.set_array(alpha)
会产生IndexError: tuple index out of range
。如果len(shape) != 2 and shape[1] != 3:
,我不知道这意味着什么。当我尝试您的示例和一个4元素数组时,它能够工作... - endolith