-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcombine_new_plots.py
executable file
·162 lines (123 loc) · 3.48 KB
/
combine_new_plots.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/python
## we assume that the long dimension is closer to filling a page than the short
## dimension
import string
from os import system,popen,chdir
from os.path import exists
from glob import glob
from random import random
import sys
from math import floor
def Help():
print
print '-'*75
print 'Usage:\n\n',sys.argv[0],'<composite-plot> <N> <input-plot1> {<input-plot2> ... }\n'
print 'for N by N plotting'
print '-'*75
print
assert 0==1
if len(sys.argv) == 1:
Help()
args = sys.argv[1:]
by_width = 0
if '-w' in args:
by_width = 1
pos = args.index('-w')
del args[pos]
LANDSCAPE = 0
if '-landscape' in args:
by_width = 0
pos = args.index('-landscape')
del args[pos]
LANDSCAPE = 1
out_file = args[0]
N = int(args[1])
L = N
try:
W = int( args[2])
plots = args[3:]
except:
W = N
plots = args[2:]
SIDEWAYS = 1
if SIDEWAYS:
W_OLD = W
W = L
L = W_OLD
for plot in plots:
if not exists(plot):
print plot+' DOES NOT EXIST.'
Help()
if exists(out_file):
print
# print '!!!!!!!!!!!!!!!!!!!!',out_file,'already exists!!!!!!!!!!!!\n'
system('rm '+out_file);
# if out_file in plots:
# plots.remove(out_file)
# print plots
# Help()
print
print '-'*75
print 'Combining',string.join(plots,'\n '),'\n\n...into',out_file
print '-'*75
print
def MakePage(out,old_plots,L,W,size,by_width):
plots = old_plots+['']*(L*W-len(old_plots))
out.write('\\begin{tabular}{'+'c'*W+'}\n')
for i in range(L):
for j in range(W):
if SIDEWAYS: out.write('\\begin{sideways}\n')
if plots[W*i+j]:
if by_width:
out.write('\\epsfxsize='+size+'\n\\epsfbox{'+plots[W*i+j]+'}\n')
else:
out.write('\\epsfysize='+size+'\n\\epsfbox{'+plots[W*i+j]+'}\n')
if SIDEWAYS: out.write('\\end{sideways}\n')
if (j+1)%W: out.write('&\n')
out.write('\\\\\n')
out.write('\\end{tabular}\n')
return
base_name = 'junk_combine_plots_'+str(random())
out = open(base_name+'.tex','w')
out.write('\\documentclass{article}\n')
out.write('\\usepackage{epsf}\n')
out.write('\\usepackage{rotating}\n')
out.write('\\textwidth=8.5in\n')
out.write('\\textheight=11in\n')
if not LANDSCAPE:
out.write('\\topmargin=-0.5in\n')
out.write('\\oddsidemargin=-1in\n')
out.write('\\evensidemargin=-1in\n')
else:
out.write('\\topmargin=-1in\n')
out.write('\\oddsidemargin=-0.5in\n')
out.write('\\evensidemargin=-0.5in\n')
out.write('\\pagestyle{empty}\n')
out.write('\\begin{document}\n')
PLOTS_PER_PAGE = L*W
#print by_width
if not LANDSCAPE:
if not by_width:
SIZE = str( 0.1*(10*10/L))+'in'
else:
SIZE = str( 0.1*(floor(70.0/W)))+'in'
else:
if not by_width:
SIZE = str( 0.1*(10*10/W))+'in'
else:
SIZE = str( 0.1*(floor(70.0/L)))+'in'
for i in range((len(plots)-1)/PLOTS_PER_PAGE +1):
MakePage(out,plots[i*PLOTS_PER_PAGE:i*PLOTS_PER_PAGE+PLOTS_PER_PAGE],
L,W,SIZE,by_width)
out.write('\n\n\n')
out.write('\\end{document}\n')
out.close()
system('latex '+base_name+'.tex 2> /dev/null > /dev/null')
assert exists(base_name+'.dvi')
landscape_tag = ''
if LANDSCAPE: landscape_tag = '-t landscape'
system('dvips '+landscape_tag+' -o '+out_file+' '+base_name+'.dvi 2> /dev/null > /dev/null')
system('rm '+base_name+'.dvi')
system('rm '+base_name+'.tex')
system('rm '+base_name+'.log')
system('rm '+base_name+'.aux')