python - Unable to plot the data calculated from elements of each row from a data file -


i have data file contains 4 elements per row kev, keverror, counts , countserror , each element separated space. each row, want calculate hertz(hz) , flux density(fnu) using these 4 elements , plot them. so, after reading 4 elements of row, want calculate hz kev(simple multiplication) , use hz value calculate fnu multiplying counts value same row. write output in file. code able calculate hz written output txt file matches manually calculated values produced plot showing different values.

first few lines of file :

   kev        kev error    counts       counts error 0.616850019 7.29998946e-3 6.82969764e-2 5.15005877e-3 0.631449997 7.30001926e-3 7.20156059e-2 5.33540128e-3 0.646049976 7.29998946e-3 8.04692879e-2 5.47288591e-3 0.65882504 5.47501445e-3 0.102332868 7.17073539e-3 

my inexperienced attempt @ code writing goes this:

import numpy np import matplotlib.pyplot plt  (kev,keverr,cts,ctserr)=np.loadtxt("sedtotal.dat", usecols=(0,1,2,3),unpack=true)  hz=kev*2.415e17 hzerr=keverr*2.415e17  fnu=kev*cts*1.602e-9 fnuerr=kev*ctserr*1.602e-9  nufnu=hz*fnu nufnuerr=hz*fnuerr  plt.figure(1) plt.ylabel(r'log $\nu$f$\nu$ (jy-hz)',fontsize = 12) plt.xlabel(r'log $\nu$ (hz)',fontsize =12)  print(hz,fnu)  plt.errorbar(hz,hzerr,fnu,fnuerr, fmt='ro', color="red", elinewidth=none, capsize=3,barsabove=true)  plt.yscale('log') plt.xscale('log')  f = open('sedtotal.txt', 'w') print >> f, 'filename:', hz, fnu, fnuerr  # write output in file f.close()  ax = plt.gca() plt.show() 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -