7

I have the following data in result.csv file, and I need to plot into a line graph.

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.

3 Answers 3

8

First, you need to separate your data using a comma, to make it an actual 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: enter image description here

When you add more data and run the code again it should automatically appear without any change in code.

Sign up to request clarification or add additional context in comments.

1 Comment

Follow up question, I need to add a column to show the date data is collected, so I want to graph everything EXCEPT the first column. Can I iterate through the csv file object and skip the first column?
4
from matplotlib import pyplot as plt
from matplotlib import style

from numpy import genfromtxt

data = genfromtxt('example2.csv',delimiter=' ')

plt.plot(data)

plt.title('Epic Info')
plt.ylabel('Y axis')
plt.xlabel('X axis')

plt.show()

The above code generated this :: enter image description here

1 Comment

Upvoted because this uses the original question's data as-is.
3
data = np.genfromtxt('path_to_data', delimiter=',', names=['x', 'y'])
plt.plot(data['x'], data['y'])
plt.show()

That's it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.