Wie der Titel schon sagt, anstelle eines φ (..) Memos.
def margin( n, nhor, nver ) :
'''
return top, bottom, left and right margins for the gnuplot command to describe diagrams as tile like arrangement.\n
inputs: n is the number of diagrams and nhor is the number of column.
'''
def margin_fmt( t, b, l, r ) :
return [ "set tmargin %d" % t, # top
"set bmargin %d" % b, # bottom
"set lmargin %d" % l, # left
"set rmargin %d" % r ]# right
ret = []
for i in range(n) :
t,b,l,r = 0,0,0,0
# vertical orientation
if i / nhor == 0 :
t = 2
elif i / nhor == nver - 1 :
b = 2
# horizontal orientation
if i % nhor == 0 :
l = 2
elif i % nhor == nhor - 1 :
r = 2
ret.append( margin_fmt( t, b, l, r ) )
return ret
if __name__ == "__main__" :
n = 2*6
nhor = 5
def get_the_number_of_rows( n, nhor ) :
if n % nhor == 0 : nver = n / nhor
elif n % nhor != 0 : nver = n / nhor + 1
return nver
nver = get_the_number_of_rows(n,nhor)
for _ in margin(n,nhor,nver) :
print _
Das Ausführungsergebnis ist wie folgt.
['set tmargin 2', 'set bmargin 0', 'set lmargin 2', 'set tmargin 0']
['set tmargin 2', 'set bmargin 0', 'set lmargin 0', 'set tmargin 0']
['set tmargin 2', 'set bmargin 0', 'set lmargin 0', 'set tmargin 0']
['set tmargin 2', 'set bmargin 0', 'set lmargin 0', 'set tmargin 0']
['set tmargin 2', 'set bmargin 0', 'set lmargin 0', 'set tmargin 2']
['set tmargin 0', 'set bmargin 0', 'set lmargin 2', 'set tmargin 0']
['set tmargin 0', 'set bmargin 0', 'set lmargin 0', 'set tmargin 0']
['set tmargin 0', 'set bmargin 0', 'set lmargin 0', 'set tmargin 0']
['set tmargin 0', 'set bmargin 0', 'set lmargin 0', 'set tmargin 0']
['set tmargin 0', 'set bmargin 0', 'set lmargin 0', 'set tmargin 2']
['set tmargin 0', 'set bmargin 2', 'set lmargin 2', 'set tmargin 0']
['set tmargin 0', 'set bmargin 2', 'set lmargin 0', 'set tmargin 0']
Recommended Posts