Hi,
I have some data like this, Actualy bigger than this more than this column and more than this rows.

Run1    Run2    Run3    RUN4    Run5
1       23      123     1234    12.33
2       12      124     1225    13.123
3       15      125     1345    32.32
4       18      135     1456    12.23
5       19      137     1563    12.43
6       12      141     1563    323.4
7       13      146     1246    23.43
8       17      151     1356    12.43
9       14      154     1355    123.3
10      16      146     1743    12.34

to plot these data I use the code as follows


import sys
import matplotlib.pyplot as plt
import numpy as np
import pylab as pl
f=open('c:/py/new3.txt')
data= np.loadtxt(f,type ,delimiter= None , skiprows=1, usecols=None)
dtype=np.array([0,1,2],dtype='int32')



"""dtype = base datatype to cast data to
delimiter = character used to specify boundry between fields
skiprows = number of leading rows to skip (in case you need to skip headers)
usecols = tuple indicating the specific columns of data you wish to extract"""

x=data[:,0]# read the whole first column
y=data[:,1]# read the whole second column
z=data[:,2]# read the whole third column
a=data[:,3]
pl.figure('abhi2')
pl.plot(x,...,y)
pl.plot(x,y,'r')
pl.plot(x,z,'g')
pl.plot(x,a,'b')
pl.xlabel('days')
pl.ylabel('yield')
pl.title('ABhifirst graph')
pl.show()
pl.savefig('abhi2.png')

from above i could able to plot up to four column of data and if i did same, might be i could plot some more column. But , question ? my column number is very big which i cant define each as above. I think i should make a loop to read each column. I would be happy if some one help me to find the code.

Thank you

Try something like this ...

# plot some collected data

import sys
import matplotlib.pyplot as plt
import numpy as np
import pylab as pl

raw_data = '''\
Run1    Run2    Run3    RUN4    Run5
1       23      123     1234    12.33
2       12      124     1225    13.123
3       15      125     1345    32.32
4       18      135     1456    12.23
5       19      137     1563    12.43
6       12      141     1563    323.4
7       13      146     1246    23.43
8       17      151     1356    12.43
9       14      154     1355    123.3
10      16      146     1743    12.34
'''

fname = 'new3.txt'

# write the test file
with open(fname, 'w') as fout:
    fout.write(raw_data)


# read the test file
f = open(fname)
"""
dtype = base datatype to cast data to
delimiter = character used to specify boundry between fields
skiprows = number of leading rows to skip (in case you need to skip headers)
usecols = tuple indicating the specific columns of data you wish to extract
"""
data = np.loadtxt(f,type , delimiter=None , skiprows=1, usecols=None)
dtype = np.array([0,1,2], dtype='int32')

print('-'*40)
print(data)   # test
print('-'*40)


pl.figure('abhi2')

# add more colors as needed
colors = 'yrgbmyrgbm'
for k in range(1, len(data[0])):
    print(k, data[:,k])  # test
    pl.plot(data[:,0], data[:,k], colors[k])


pl.xlabel('days')
pl.ylabel('yield')
pl.title('AB hifirst graph')

pl.show()


#pl.savefig('abhi2.png')
This article has been dead for over six months. Start a new discussion instead.