python - Plotting data from input file from command line -
python - Plotting data from input file from command line -
i have been given info file called "density_air.dat" , need take info each column , set them own lists (ie tlist hold values in column starting "-10" , density hold values in column starting "1.341". lists need plotted. having problem populating lists data...any help?
from scitools.std import * import sys import pylab pl infile = sys.argv[-1] f = open(infile, 'r') x in range(4): f.readline() tlist = [] density = [] line in f: words = line.split() x in words: tlist.append(words[x]) density.append(words[x]) f.close() plot(tlist, density)
the info file is:
# density of air @ different temperatures, @ 1 atm pressure level # column 1: temperature in celsius degrees # column 2: density in kg/m^3 -10 1.341 -5 1.316 0 1.293 5 1.269 10 1.247 15 1.225 20 1.204 25 1.184 30 1.164 # source: wikipedia (keyword density)
there numpy
function called loadtxt
loads ascii files numpy
arrays:
import numpy np import matplotlib.pylab plt import sys infile = sys.argv[-1] temperature, density = np.loadtxt(infile,unpack=true) plt.plot(temperature, density,'ko') plt.show()
python matplotlib plot
Comments
Post a Comment