0

So I have a set of data which has a singular column for x data and multiple columns for y data, of the form.

x_title     y_title_1    y_title_2   y_title_3 ....   y_title_n
data_x1     data_y2      data_y3     data_y4          data_yn
....        ....         ....        ....      ....   ....

I am trying to graph the data, a different plot for each y_data_i, on the same graph.

I am using numpy arrays, matplotlib and scipy. And genfromtxt to read it in. I imagine the best way would be to put each column into an array, so there is an array for y_data_1,y_data_2 and so on. However I have no idea how to do this? I know how to read them in singularly, to a set data, so:

y_data_1=data[0:number_of_rows,1] 

However I don't know how to code a way to do it for hundreds of columns.

pythonman11
  • 1
  • 1
  • 5

2 Answers2

0

The basic plotting function would be:

import matplotlib.pyplot as plt
x = data[0]
for y in data[1:]:
    plt.plot(x, y)
plt.show()

where data[0] is your first column, and data[1:] is everything except the first column.

See here for more options.

Community
  • 1
  • 1
philshem
  • 24,761
  • 8
  • 61
  • 127
  • Ah didn't realise you could plot as simply as that! However how would I put the columns into arrays instead of straight plotting? I would like to do some procedures to the data before plotting. – pythonman11 Apr 29 '15 at 14:13
  • also i noticed that doesn't actually plot data, but the values for all of the first rows. – pythonman11 Apr 29 '15 at 14:58
0
>>>import pandas as pd
>>>create a new series
>>>ser1 = pd.Series()
>>>col = [x for x in df.columns]
   df is values of csv data 
>>>for i in range(N):
   N is no of columns
   >>>ser1 = ser1.append(df[i])
Amit Kumar
  • 619
  • 7
  • 10