Author Topic: Saving data from script  (Read 2831 times)

0 Members and 1 Guest are viewing this topic.

Offline ams_nanolab

  • Supreme QuantumATK Wizard
  • *****
  • Posts: 389
  • Country: in
  • Reputation: 11
    • View Profile
Saving data from script
« on: August 6, 2015, 14:05 »
I have a python script to see a plot in ATK, but I cant save it into a data file, here's the plot command
--------------------------------------
# Plot the data
import pylab
pylab.plot(energ,alpha,'b', label='plot')
pylab.xlabel(r"Energy (eV)", size=16)
pylab.ylabel(r"alpha",size=16)
pylab.show()
-------------------------

I want to save the data for plotting into a .dat file , consisting of two columns .. how do I do that?

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: Saving data from script
« Reply #1 on: August 7, 2015, 01:29 »
This is pretty basic Python...
Code: python
with open("alpha.dat", "w") as f:
    for e,a in zip(energy,alpha):
        f.write("%g\t%g\n" % (e,a))
Of course it can be done less elegantly, and perhaps easier to understand:
Code: python
f = open("alpha.dat", "w")
for i in range(len(energy)):
    s = str(energy[i]) + "\t" + str(alpha[i])
    f.write(s+"\n")
f.close()
« Last Edit: August 7, 2015, 01:32 by Anders Blom »

Offline ams_nanolab

  • Supreme QuantumATK Wizard
  • *****
  • Posts: 389
  • Country: in
  • Reputation: 11
    • View Profile
Re: Saving data from script
« Reply #2 on: August 7, 2015, 13:51 »
Thanks.