[英]Plotting csv file data to line graph using matplotlib
I have the following data in result.csv file, and I need to plot into a line graph. 我在result.csv文件中有以下数据,我需要绘制成线图。
ColA ColB
93 46
94 56
95 66
97 76
100 86
103 96
110 106
What I have is 我拥有的是什么
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()
How do feed each column of data into the graph and see its trend? 如何将每列数据输入图表并查看其趋势? The size if each column will grow daily because of new data.
每列因新数据而每天都会增长的大小。
First, you need to separate your data using a comma, to make it an actual csv. 首先,您需要使用逗号分隔数据,以使其成为实际的csv。 Then add the missing closing brace at the end of this line:
然后在此行的末尾添加缺少的右括号:
per_data=genfromtxt('result.csv',delimiter=',')
and plot the data using 并使用绘制数据
plt.plot(per_data)
This results in this plot: 这导致了这个情节:
When you add more data and run the code again it should automatically appear without any change in code. 当您添加更多数据并再次运行代码时,它应自动显示而不会对代码进行任何更改。
data = np.genfromtxt('path_to_data', delimiter=',', names=['x', 'y'])
plt.plot(data['x'], data['y'])
plt.show()
That's it. 而已。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.