gpt4 book ai didi

python - 使用 matplotlib 将 csv 文件数据绘制成折线图

转载 作者:太空狗 更新时间:2023-10-30 01:50:35 25 4
gpt4 key购买 nike

我在 result.csv 文件中有以下数据,我需要绘制成折线图。

ColA    ColB
93 46
94 56
95 66
97 76
100 86
103 96
110 106

我有的是

from numpy import genfromtxt
import matplotlib.pyplot as plt
per_data=genfromtxt('result.csv',delimiter=','
plt.xlabel ('x stuff')
plt.ylabel ('y stuff')
plt.title('my test result')
plt.show()

如何将每一列数据输入图表并查看其趋势?由于新数据,每列每天都会增长的大小。

最佳答案

首先,您需要使用逗号分隔数据,使其成为实际的 csv。然后在此行的末尾添加缺少的右大括号:

per_data=genfromtxt('result.csv',delimiter=',')

并使用

绘制数据
plt.plot(per_data)

这导致了这个情节: enter image description here

当您添加更多数据并再次运行代码时,它应该自动出现而无需更改代码。

关于python - 使用 matplotlib 将 csv 文件数据绘制成折线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36872136/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com