[PYTHON] A script that combines margins when pasting a number of graphs on tiles with gnuplot

As the title says, instead of a φ (..) memo.

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 _

The execution result is as follows.

['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

A script that combines margins when pasting a number of graphs on tiles with gnuplot
A script that combines multiple pages of a PDF file into one page without margins
A script that pings the registered server and sends an email with Gmail a certain number of times when it fails
When generating a large number of graphs with matplotlib, I do not want to display the graph on the screen (jupyter environment)
A story that I had a hard time displaying graphs on top of each other with matplotlib
A python script that gets the number of jobs for a specified condition from indeed.com
A script that can perform stress tests according to the number of CPU cores
[Shell art] Only when it is a multiple of 3 and a number with 3 becomes stupid
A tool to follow posters with a large number of likes on instagram [25 minutes to 1 second]
[Grasshopper] When creating a data tree on Python script
[Python] A program that counts the number of valleys
A script that takes a snapshot of an EBS volume
What's in that variable (when running a Python script)
A script that outputs a list of SoftLayer portal users
Script that changes the length of the sound with REAPER
A server that returns the number of people in front of the camera with bottle.py and OpenCV
Create a bot that only returns the result of morphological analysis with MeCab on Discord
Summary of points to keep in mind when writing a program that runs on Python 2.5
About the contents of wscript when building a D language environment like that with Waf
Workaround for the problem that sys.argv is not passed when executing a Python script with only the file name in Python2.7 on Windows