我正在阅读一个不断更新的data.txt
文件,并正在计算传入数据流的滚动标准偏差。我将其存储在std
. 我在滚动标准偏差上的窗口大小为 100。
我收到一个错误:
ValueError: cannot copy sequence with size 78 to array axis with dimension 1
其中大小对应于std
数组中的项目数。(所以,当然,每次我点击 Run 时都会增加)。
我想知道为什么我会收到这个 ValueError,并且正在寻找任何修复它的建议!当我只是分级时,动画效果很好ax1.plot(xar, yar)
。但是一旦我尝试绘制图表ax1.plot(xar, std)
,问题就出现了。
中的数据data.txt
如下所示:
[0.0, 0.0078125, 0.015625][0.0, 0.0078125, 0.015625][0.0, 0.0078125, 0.015625][0.0, 0.0078125, 0.015625][0.0, 0.0078125, 0.015625][0.0, 0.0078125, 0.015625][0.0244140625, 0.0322265625, 0.9609375][0.0244140625, 0.0322265625, 0.9609375][0.0244140625, 0.0322265625, 0.9609375][0.0244140625, 0.0322265625, 0.9609375][0.0244140625, 0.0322265625, 0.9609375][0.0244140625, 0.0322265625, 0.9609375][0.0244140625, 0.0322265625, 0.9609375][0.0244140625, 0.0322265625, 0.9609375][0.0244140625, 0.0322265625, 0.9609375][0.0263671875, 0.0341796875, 1.0341796875][0.0263671875, 0.0341796875, 1.0341796875][0.0263671875, 0.0341796875, 1.0341796875][0.0263671875, 0.0341796875, 1.0341796875][0.0263671875, 0.0341796875, 1.0341796875][0.0263671875, 0.0341796875, 1.0341796875][0.0263671875, 0.0341796875, 1.0341796875][0.0263671875, 0.0341796875, 1.0341796875][0.0244140625, 0.0341796875, 1.0048828125][0.0244140625, 0.0341796875, 1.0048828125][0.0244140625, 0.0341796875, 1.0048828125][0.0244140625, 0.0341796875, 1.0048828125][0.0244140625, 0.0341796875, 1.0048828125][0.0244140625, 0.0341796875, 1.0048828125][0.0244140625, 0.0341796875, 1.0048828125][0.0244140625, 0.0341796875, 1.0048828125][0.0244140625, 0.0341796875, 1.0048828125][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.033203125, 1.009765625][0.025390625, 0.033203125, 1.009765625][0.025390625, 0.033203125, 1.009765625][0.025390625, 0.033203125, 1.009765625][0.025390625, 0.033203125, 1.009765625][0.025390625, 0.033203125, 1.009765625][0.025390625, 0.033203125, 1.009765625][0.025390625, 0.033203125, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.0263671875, 0.0341796875, 1.009765625][0.0263671875, 0.0341796875, 1.009765625][0.0263671875, 0.0341796875, 1.009765625][0.0263671875, 0.0341796875, 1.009765625][0.0263671875, 0.0341796875, 1.009765625][0.0263671875, 0.0341796875, 1.009765625][0.0263671875, 0.0341796875, 1.009765625][0.0263671875, 0.0341796875, 1.009765625][0.0263671875, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.0107421875][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625][0.025390625, 0.0341796875, 1.009765625]
我目前的代码如下:
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
def animate(i):
data = pd.read_csv("C:\\Users\\Desktop\\data.txt", sep="\[|\]\[|\]",engine = 'python', header = None)
data = data.iloc[0]
data = data.astype(str).apply(lambda x: x.split(',')[-1]).astype(float)
data.pop(0)
xar = []
yar = []
std = []
for j in range(len(data)):
xar.append(j)
for k in range(len(data)):
yar.append(data.iloc[k])
yar = pd.DataFrame(yar)
std.append(pd.rolling_std(yar, 100))
ax1.clear()
ax1.plot(xar,std)
ani = animation.FuncAnimation(fig, animate, interval=.01)
plt.show()