Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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.

like image 746
Peter Chao Avatar asked Apr 26 '16 17:04

Peter Chao


2 Answers

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.

like image 173
sietschie Avatar answered Nov 07 '22 20:11

sietschie


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

like image 42
Akash Kandpal Avatar answered Nov 07 '22 20:11

Akash Kandpal