拥有for循环的最佳方法是创建.dat文件

时间:2017-07-17 18:27:03

标签: python

我试图让for循环使用for循环写出自定义.dat文件,从.dat文件创建一个png图像。我的代码如下所示。我对此比较陌生。非常感谢所有帮助。

def MDNBR(self):
    self.filename = "MDNBR.gnu"
    self.figurename = "MDNBR.png"
    self.datafile = "MDNBR.dat"

    #-- post process / get data from XML file
    with open(self.datafile, 'w') as f:
        f.write('# Cycle  Limit  CEA Ejection  Dropped Control Rod or Bank  Increase in Steam Flow  Uncontrolled CEA Withdrawal from Power\n')

        for cycle in past_cycle_data:
            tmp = []
            for fsar_id in ["14.13"]:
                for event in past_cycle_data[cycle].autodnb.result:
                    if fsar_id == event["fsar_id"]: tmp.append(event["mdnbr"])
            f.write('{} {} {}\n'.format(cycle,'1.141',' '.join(tmp)))

    self.output = textwrap.dedent('''\
    set terminal png size 800,600 
    set output "{0}" 
    set grid 
    set xlabel "Cycle" 
    set title "MDNBR" 
    set xtics (24,25,26,27)
    set yrange[1.1:1.6]
    plot "{1}" using 1:2 title 'CHF Limit' w linespoints lt 0 lc -1 lw 2 pt 0, "{1}" u 1:3 t 'CEA Ejection' w linespoints lt 3 lw 2 pt 7 ps 1, "{1}" u 1:4 t 'Dropped Control Rod or Bank' w linespoints lt 10 lw 2 pt 9 ps 1, "{1}" u 1:5 t 'Increase in Steam Flow' w linespoints lt 4 lw 2 pt 2 ps 1, "{1}" u 1:6 t 'Uncontrolled CEA Withdrawal from Power' w linespoints lt 1 lw 2 pt 5 ps 1
    '''.format(self.figurename, self.datafile))
    pass

0 个答案:

没有答案