import Gnuplot, argparse parser=argparse.ArgumentParser(description='Reads a file and split lines to words.') parser.add_argument('filename',help='name of the file') parser.add_argument("--title",help='title of the plot') parser.add_argument("--out",help='name of the output file') parser.add_argument("--yaxis",help='title of the y axis') args = parser.parse_args() g=Gnuplot.Gnuplot() #file=open("pics/horiz_line_plots.txt",'r') file=open(args.filename,'r') x=[] y=[] title=[] for line in file: words=line.split() if words[0]=='%': continue if words[0]=='0': x.append([]) y.append([]) x[len(x)-1].append(float(words[0])) y[len(y)-1].append(float(words[1])) title.append("360 V/cm") data=Gnuplot.Data(x[0],y[0],title=title[0]) g('set style data lines') g('set xrange [0:25]') g('set yrange [340:370]') #g('set key font "0.2,4"') g('set key outside box') if args.title != None: g('set title "'+args.title) g('set xlabel "Distance (mm)"') if args.yaxis != None: print args.yaxis g('set ylabel "'+str(args.yaxis)+'"') g.plot(data) for i in range(len(x)-1): title.append(str(360+(i+1)*10)+" V/cm") data=Gnuplot.Data(x[i+1],y[i+1],title=title[i+1]) g('set style data lines') # g('set key font "0.2,4"') g.replot(data) func=Gnuplot.Func('360' 'lw 4 notitle') g.replot(func) #g('set size 1.0, 0.6') g('set terminal postscript landscape enhanced dashed color lw 1 "Helvetica" 14') g.replot() if args.out != None: print args.out g('set output "'+args.out+'"') g.replot() # g.hardcopy(filename=args.out,terminal="ps") else: g.hardcopy(filename="pyplot.png",terminal="png") bla=raw_input("done?")