根据错误提示,无法将字符串转换为浮点数,可能是由于字符串中包含空格导致的。因此,需要在读取数据时将空格去掉。

修改代码如下:

读取文件中的数据

x = [] y = [] with open('get_mem.txt', 'r') as f: for line in f: data = line.strip().replace(' ', '').split(',') print(data) x.append(float(data[0])) y.append(float(data[1].replace('%', '')))

绘制曲线图

plt.plot(x, y) plt.xlabel('X Axis') plt.ylabel('Y Axis') plt.title('Curve') plt.show()

修改后的代码中使用 replace() 方法将空格和百分号去掉,并使用 float() 将数据转换为浮点数。


原文地址: https://www.cveoy.top/t/topic/c9sg 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录