-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgnuplot.py
executable file
·47 lines (36 loc) · 974 Bytes
/
gnuplot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
import sys
import re
from subprocess import Popen, PIPE
text = '''
set title "%(title)s" font "Times-New-Roman,24"
set terminal pngcairo size 900,900 font "Helvetica,14"
set output "%(output)s"
set xrange [%(xrange)s]
set yrange [%(yrange)s]
plot "%(file)s" using 1:2 pt 7 ps 0.8 notitle,\
"%(exact)s" using 1:2 with lines title "Exact front"
print("%(file)s > %(output)s")
'''
params = {
'xrange': '0:1',
'yrange': '0:10',
}
def get_step(name):
nums = re.findall(r'\d+', name)
return nums[0] if nums else '(?)'
p = Popen(['gnuplot'], shell=True, stdin=PIPE)
exact = sys.argv[1]
for name in sys.argv[2:]:
out = name.replace('.dat', '.png')
step = get_step(name)
title = 'Step %s' % step
conf = {
'file': name,
'output': out,
'title': title,
'exact': exact,
}
cmd = text % dict(params, **conf)
p.stdin.write(cmd)
p.communicate()