ValueError: Could not convert string to float: "nbformat":4

ValueError: Could not convert string to float: "nbformat":4

经过长时间的计算,我得到了包含以下字符串的文件。

(每个字符串以“\t”分隔,每行末尾有“\n”。)

0.0000008375000 829.685601736   555.939928236
0.0000008376000 829.511081539   555.889353246
0.0000008377000 829.336613968   555.838785601
0.0000008378000 829.162199002   555.7882253
0.0000008379000 828.987836621   555.737672342
0.0000008380000 828.813526805   555.687126727
0.0000008381000 828.639269533   555.636588453

然后我尝试绘制这些文件。 (文件名以 P 开头。)

fList = np.array(gl.glob("P*"))
for i in fList:
    f = open(i, "r")
    data = f.read()
    data = data.replace("\n", "\t")
    data = np.array(data.split("\t"))[:-1].reshape(-1,3)
    plt.plot(data[:,0], data[:,1], label=i)

然后我遇到了以下错误。

(错误指针表明这发生在行 plt.plot(data[:,0], data[:,1], label=i))

ValueError: could not convert string to float: "nbformat": 4,

我查阅了其他一些教程或演练,但不幸的是,无法理解如何解决此问题。任何帮助或建议将不胜感激。

可以直接用numpy将文件读入三个数组:

import numpy as np
import matplotlib.pyplot as plt
from glob import glob

fList = glob("P*")
for i in fList:
    x,y,z = np.loadtxt(i, unpack=True)
    plt.plot(x,y, label=i)

plt.legend()
plt.show()