コード例 #1
0
ファイル: ds.py プロジェクト: Enucatl/lab-unipd
 def grafico(self, other, \
             interp='n', \
             cifre=('"%.0s*10^{%S}"','"%.0s*10^{%S}"'), \
             terminal='x11', \
             etichetteassi=('x', 'y'), \
             output='grafico'):
     glt = Gnuplot.Gnuplot(debug=1)  #apre gnuplot
     glt('set tics nomirror; unset key; set format x %s; set format y %s' %
         cifre)
     glt('set terminal %s' % terminal)
     glt('set output "%s"' % output)
     glt.xlabel(etichetteassi[0])
     glt.ylabel(etichetteassi[1])
     nome = 'temp'
     colonne = (1, 2)
     scrivivalori((self.valori, other.valori), nome)
     if interp != 'n':
         parametri = self.interpolazionelineare(other)
         f = Gnuplot.Func('%.14f*x%+.14f' % (parametri[2], parametri[0]))
         glt.plot(Gnuplot.File(nome, using=colonne), f)
         if terminal == 'x11': chiudigrafico()
         return
     glt.plot(Gnuplot.File(nome, using=colonne))
     glt('set output')
     if terminal == 'x11': chiudigrafico()
コード例 #2
0
ファイル: test.py プロジェクト: vishalbelsare/ompc
def main():
    """Exercise the Gnuplot module."""

    print (
        'This program exercises many of the features of Gnuplot.py.  The\n'
        'commands that are actually sent to gnuplot are printed for your\n'
        'enjoyment.'
        )

    wait('Popping up a blank gnuplot window on your screen.')
    g = Gnuplot.Gnuplot(debug=1)
    g.clear()

    # Make a temporary file:
    filename1 = tempfile.mktemp()
    f = open(filename1, 'w')
    try:
        for x in Numeric.arange(100)/5. - 10.:
            f.write('%s %s %s\n' % (x, math.cos(x), math.sin(x)))
        f.close()

        print '############### test Func ###################################'
        wait('Plot a gnuplot-generated function')
        g.plot(Gnuplot.Func('sin(x)'))

        wait('Set title and axis labels and try replot()')
        g.title('Title')
        g.xlabel('x')
        g.ylabel('y')
        g.replot()

        wait('Style linespoints')
        g.plot(Gnuplot.Func('sin(x)', with='linespoints'))
コード例 #3
0
def plot_line(m, b, xrange=None, yrange=None):
    """plot a line with slope m and bias b, currently using Gnuplot"""
    if(G):
        line = Gnuplot.Func ('%f + (%f) * x' % (b, m))
        if xrange: G.set_range('xrange', xrange)
        if yrange: G.set_range('yrange', yrange)
        G.plot(line)
        wait_for_input()
コード例 #4
0
ファイル: GnuplotDemo.py プロジェクト: EJHortala/books-2
def demo():
    g = Gnuplot.Gnuplot(debug=1)
    g.title('A simple example')  # (optional)
    g('set data style linespoints')  # give gnuplot an arbitrary command
    # Plot a list of (x, y)  (tuples or a numpy array would also be OK):
    g.plot([[0, 1.1], [1, 5.8], [2, 3.3], [3, 4.2]])
    raw_input('Please press return to continue...\n')

    g.reset()
    x = arange(10, dtype='float_')
    y1 = x**2
    d = Gnuplot.Data(x, y1, title='Calculated by Python', with_='points 3 3')
    g.title('Data can be computed by Python or gnuplot')
    g.xlabel('x')
    g.ylabel('x squared')
    # Plot a function alongside the Data PlotItem defined above:
    g.plot(Gnuplot.Func('x**2', title='calculated by gnuplot'), d)
    raw_input('Please press return to continue...\n')

    # Save what we just plotted as a color postscript file.
    g.ylabel('x^2')
    g.hardcopy('gp_test.ps', enhanced=1, color=1)
    print('\n**** Saved plot to postscript file "gp_test.ps" ******\n')
    raw_input('Please press return to continue...\n')

    g.reset()
    # Demonstrate a 3-d plot:
    x = arange(35) / 2.0
    y = arange(30) / 10.0 - 1.5
    # Make a 2-d array containing a function of x and y.  First create
    # xm and ym which contain the x and y values in a matrix form
    xm = x[:, newaxis]
    ym = y[newaxis, :]
    m = (sin(xm) + 0.1 * xm) - ym**2
    g('set parametric')
    g('set data style lines')
    g('set hidden')
    g('set contour base')
    g.title('An example of a surface plot')
    g.xlabel('x')
    g.ylabel('y')

    g.splot(Gnuplot.GridData(m, x, y, binary=0))
    raw_input('Please press return to continue...\n')

    # plot another function, but letting GridFunc tabulate its values
    def f(x, y):
        return 1.0 / (1 + 0.01 * x**2 + 0.5 * y**2)

    g.splot(Gnuplot.funcutils.compute_GridData(x, y, f, binary=0))
    raw_input('Please press return to continue...\n')
コード例 #5
0
def grafico(nomefile,
            colonne=(1, 2),
            etichetteassi=('x', 'y'),
            cifredecimali=('.g', '.g')):
    decimali = ('"%' + cifredecimali[0] + '"', '"%' + cifredecimali[1] + '"')
    (x, y) = legginumeri(nomefile, colonne)
    parametri = interpolazionelineare(x, y)
    f = Gnuplot.Func('%.14f*x%+.14f' % (parametri[2], parametri[0]))
    glt = Gnuplot.Gnuplot(debug=1)  #apre gnuplot
    glt('set tics nomirror;unset key;set format x %s;set format y %s' %
        decimali)
    glt.xlabel(etichetteassi[0])
    glt.ylabel(etichetteassi[1])
    glt.plot(Gnuplot.File(nomefile, using=colonne), f)
コード例 #6
0
 def Plot(self):
     g = Gnuplot.Gnuplot()
     g.clear()
     plots = []
     color = 1
     g.xlabel('time (seconds)')
     for plot in self.plots:
         fn = plot.WriteToTempFile()
         g.ylabel(plot.title)
         plots.append(Gnuplot.File(fn, with_='lines linecolor %d' % color, title='%s (%.2f - %.2f)' % (plot.title, plot.min, plot.max)))
         if plot.IsMidLineVisible():
             plots.append(Gnuplot.Func('%.4f' % plot.GetMidLine(), with_='lines linecolor %d' % color, title=''))
         color += 1
     g.plot(*plots)
     wait()
コード例 #7
0
def graficoPST(nomefile,
               colonne=(1, 2),
               etichetteassi=('x', 'y'),
               cifredecimali=('.g', '.g')):
    glt = Gnuplot.Gnuplot(debug=1)  #apre gnuplot
    glt('set terminal pstricks; set output %s' % ('"' + nomefile + '.tex"'))
    decimali = ('"%' + cifredecimali[0] + '"', '"%' + cifredecimali[1] + '"')
    (x, y) = legginumeri(nomefile, colonne)
    parametri = interpolazionelineare(x, y)
    f = Gnuplot.Func('%.14f*x%+.14f' % (parametri[2], parametri[0]))
    #glt = Gnuplot.Gnuplot(debug=1) #apre gnuplot
    glt('set tics nomirror;unset key;set format x %s;set format y %s' %
        decimali)
    glt('set xlabel %s; set ylabel %s' % etichetteassi)
    glt.plot(Gnuplot.File(nomefile, every=10, using=colonne), f)
    glt('set output')
コード例 #8
0
ファイル: gnuplot_data.py プロジェクト: logust79/cgat-apps
def Fit(data, cols=(0, 1)):

    import scipy.linalg

    a, b = cols

    matrix = []
    imatrix = []

    for d in data:
        matrix.append([1.0, d[a]])  # for y = a + bx
        imatrix.append([1.0, d[b]])  # for x = a + by

    coeffs = scipy.linalg.lstsq(matrix, map(lambda x: x[b], data))[0]
    icoeffs = scipy.linalg.lstsq(imatrix, map(lambda x: x[a], data))[0]

    f = "%f + %f*x" % (coeffs[0], coeffs[1])

    r2 = coeffs[1] * icoeffs[1]

    return Gnuplot.Func(f, title="%s (r^2=%f)" % (f, r2))
コード例 #9
0
def dipolePlot(dipole, freq):
    data = dipole[freq]
    cosTheta = []
    del_int = []
    for data2 in data:
        cosTheta.append(data2[0])
        del_int.append(data2[1])

    def f(
        a, x
    ):  # let's not forget to define the function we want to fit our data to
        return a * x

    soln, extra = curve_fit(f, cosTheta,
                            del_int)  #fitting fittting fitting....
    func = str(soln[0])
    g = Gnuplot.Gnuplot(debug=1)
    d = Gnuplot.Data(cosTheta, del_int)
    g.xlabel('cosTheta')
    g.ylabel('deltaI/I')
    g.plot(Gnuplot.Func(func + '*x'), d)
コード例 #10
0
ファイル: test.py プロジェクト: jwalker/gnuplot-py
def main():
    """Exercise the Gnuplot module."""

    print(
        'This program exercises many of the features of Gnuplot.py.  The\n'
        'commands that are actually sent to gnuplot are printed for your\n'
        'enjoyment.')

    wait('Popping up a blank gnuplot window on your screen.')
    g = Gnuplot.Gnuplot(debug=1)
    g.clear()

    # Make two temporary files:
    if hasattr(tempfile, 'mkstemp'):
        (
            fd,
            filename1,
        ) = tempfile.mkstemp(text=1)
        f = os.fdopen(fd, 'w')
        (
            fd,
            filename2,
        ) = tempfile.mkstemp(text=1)
    else:
        filename1 = tempfile.mktemp()
        f = open(filename1, 'w')
        filename2 = tempfile.mktemp()
    try:
        for x in numpy.arange(100.) / 5. - 10.:
            f.write('%s %s %s\n' % (x, math.cos(x), math.sin(x)))
        f.close()

        print '############### test Func ###################################'
        wait('Plot a gnuplot-generated function')
        g.plot(Gnuplot.Func('sin(x)'))

        wait('Set title and axis labels and try replot()')
        g.title('Title')
        g.xlabel('x')
        g.ylabel('y')
        g.replot()

        wait('Style linespoints')
        g.plot(Gnuplot.Func('sin(x)', with_='linespoints'))
        wait('title=None')
        g.plot(Gnuplot.Func('sin(x)', title=None))
        wait('title="Sine of x"')
        g.plot(Gnuplot.Func('sin(x)', title='Sine of x'))
        wait('axes=x2y2')
        g.plot(Gnuplot.Func('sin(x)', axes='x2y2', title='Sine of x'))

        print 'Change Func attributes after construction:'
        f = Gnuplot.Func('sin(x)')
        wait('Original')
        g.plot(f)
        wait('Style linespoints')
        f.set_option(with_='linespoints')
        g.plot(f)
        wait('title=None')
        f.set_option(title=None)
        g.plot(f)
        wait('title="Sine of x"')
        f.set_option(title='Sine of x')
        g.plot(f)
        wait('axes=x2y2')
        f.set_option(axes='x2y2')
        g.plot(f)

        print '############### test File ###################################'
        wait('Generate a File from a filename')
        g.plot(Gnuplot.File(filename1))

        wait('Style lines')
        g.plot(Gnuplot.File(filename1, with_='lines'))

        wait('using=1, using=(1,)')
        g.plot(Gnuplot.File(filename1, using=1, with_='lines'),
               Gnuplot.File(filename1, using=(1, ), with_='points'))
        wait('using=(1,2), using="1:3"')
        g.plot(Gnuplot.File(filename1, using=(1, 2)),
               Gnuplot.File(filename1, using='1:3'))

        wait('every=5, every=(5,)')
        g.plot(Gnuplot.File(filename1, every=5, with_='lines'),
               Gnuplot.File(filename1, every=(5, ), with_='points'))
        wait('every=(10,None,0), every="10::5"')
        g.plot(Gnuplot.File(filename1, with_='lines'),
               Gnuplot.File(filename1, every=(10, None, 0)),
               Gnuplot.File(filename1, every='10::5'))

        wait('title=None')
        g.plot(Gnuplot.File(filename1, title=None))
        wait('title="title"')
        g.plot(Gnuplot.File(filename1, title='title'))

        print 'Change File attributes after construction:'
        f = Gnuplot.File(filename1)
        wait('Original')
        g.plot(f)
        wait('Style linespoints')
        f.set_option(with_='linespoints')
        g.plot(f)
        wait('using=(1,3)')
        f.set_option(using=(1, 3))
        g.plot(f)
        wait('title=None')
        f.set_option(title=None)
        g.plot(f)

        print '############### test Data ###################################'
        x = numpy.arange(100) / 5. - 10.
        y1 = numpy.cos(x)
        y2 = numpy.sin(x)
        d = numpy.transpose((x, y1, y2))

        wait('Plot Data against its index')
        g.plot(Gnuplot.Data(y2, inline=0))

        wait('Plot Data, specified column-by-column')
        g.plot(Gnuplot.Data(x, y2, inline=0))
        wait('Same thing, saved to a file')
        Gnuplot.Data(x, y2, inline=0, filename=filename1)
        g.plot(Gnuplot.File(filename1))
        wait('Same thing, inline data')
        g.plot(Gnuplot.Data(x, y2, inline=1))

        wait('Plot Data, specified by an array')
        g.plot(Gnuplot.Data(d, inline=0))
        wait('Same thing, saved to a file')
        Gnuplot.Data(d, inline=0, filename=filename1)
        g.plot(Gnuplot.File(filename1))
        wait('Same thing, inline data')
        g.plot(Gnuplot.Data(d, inline=1))
        wait('with_="lp 4 4"')
        g.plot(Gnuplot.Data(d, with_='lp 4 4'))
        wait('cols=0')
        g.plot(Gnuplot.Data(d, cols=0))
        wait('cols=(0,1), cols=(0,2)')
        g.plot(Gnuplot.Data(d, cols=(0, 1), inline=0),
               Gnuplot.Data(d, cols=(0, 2), inline=0))
        wait('Same thing, saved to files')
        Gnuplot.Data(d, cols=(0, 1), inline=0, filename=filename1)
        Gnuplot.Data(d, cols=(0, 2), inline=0, filename=filename2)
        g.plot(Gnuplot.File(filename1), Gnuplot.File(filename2))
        wait('Same thing, inline data')
        g.plot(Gnuplot.Data(d, cols=(0, 1), inline=1),
               Gnuplot.Data(d, cols=(0, 2), inline=1))
        wait('Change title and replot()')
        g.title('New title')
        g.replot()
        wait('title=None')
        g.plot(Gnuplot.Data(d, title=None))
        wait('title="Cosine of x"')
        g.plot(Gnuplot.Data(d, title='Cosine of x'))

        print '############### test compute_Data ###########################'
        x = numpy.arange(100) / 5. - 10.

        wait('Plot Data, computed by Gnuplot.py')
        g.plot(
            Gnuplot.funcutils.compute_Data(x, lambda x: math.cos(x), inline=0))
        wait('Same thing, saved to a file')
        Gnuplot.funcutils.compute_Data(x,
                                       lambda x: math.cos(x),
                                       inline=0,
                                       filename=filename1)
        g.plot(Gnuplot.File(filename1))
        wait('Same thing, inline data')
        g.plot(Gnuplot.funcutils.compute_Data(x, math.cos, inline=1))
        wait('with_="lp 4 4"')
        g.plot(Gnuplot.funcutils.compute_Data(x, math.cos, with_='lp 4 4'))

        print '############### test hardcopy ###############################'
        print '******** Generating postscript file "gp_test.ps" ********'
        wait()
        g.plot(
            Gnuplot.Func('cos(0.5*x*x)',
                         with_='linespoints 2 2',
                         title='cos(0.5*x^2)'))
        g.hardcopy('gp_test.ps')

        wait('Testing hardcopy options: mode="eps"')
        g.hardcopy('gp_test.ps', mode='eps')
        wait('Testing hardcopy options: mode="landscape"')
        g.hardcopy('gp_test.ps', mode='landscape')
        wait('Testing hardcopy options: mode="portrait"')
        g.hardcopy('gp_test.ps', mode='portrait')
        wait('Testing hardcopy options: eps=1')
        g.hardcopy('gp_test.ps', eps=1)
        wait('Testing hardcopy options: mode="default"')
        g.hardcopy('gp_test.ps', mode='default')
        wait('Testing hardcopy options: enhanced=1')
        g.hardcopy('gp_test.ps', enhanced=1)
        wait('Testing hardcopy options: enhanced=0')
        g.hardcopy('gp_test.ps', enhanced=0)
        wait('Testing hardcopy options: color=1')
        g.hardcopy('gp_test.ps', color=1)
        # For some reason,
        #    g.hardcopy('gp_test.ps', color=0, solid=1)
        # doesn't work here (it doesn't activate the solid option), even
        # though the command sent to gnuplot looks correct.  I'll
        # tentatively conclude that it is a gnuplot bug. ###
        wait('Testing hardcopy options: color=0')
        g.hardcopy('gp_test.ps', color=0)
        wait('Testing hardcopy options: solid=1')
        g.hardcopy('gp_test.ps', solid=1)
        wait('Testing hardcopy options: duplexing="duplex"')
        g.hardcopy('gp_test.ps', solid=0, duplexing='duplex')
        wait('Testing hardcopy options: duplexing="defaultplex"')
        g.hardcopy('gp_test.ps', duplexing='defaultplex')
        wait('Testing hardcopy options: fontname="Times-Italic"')
        g.hardcopy('gp_test.ps', fontname='Times-Italic')
        wait('Testing hardcopy options: fontsize=20')
        g.hardcopy('gp_test.ps', fontsize=20)

        print '******** Generating svg file "gp_test.svg" ********'
        wait()
        g.plot(
            Gnuplot.Func('cos(0.5*x*x)',
                         with_='linespoints 2 2',
                         title='cos(0.5*x^2)'))
        g.hardcopy('gp_test.svg', terminal='svg')

        wait('Testing hardcopy svg options: enhanced')
        g.hardcopy('gp_test.ps', terminal='svg', enhanced='1')

        print '############### test shortcuts ##############################'
        wait('plot Func and Data using shortcuts')
        g.plot('sin(x)', d)

        print '############### test splot ##################################'
        wait('a 3-d curve')
        g.splot(Gnuplot.Data(d, with_='linesp', inline=0))
        wait('Same thing, saved to a file')
        Gnuplot.Data(d, inline=0, filename=filename1)
        g.splot(Gnuplot.File(filename1, with_='linesp'))
        wait('Same thing, inline data')
        g.splot(Gnuplot.Data(d, with_='linesp', inline=1))

        print '############### test GridData and compute_GridData ##########'
        # set up x and y values at which the function will be tabulated:
        x = numpy.arange(35) / 2.0
        y = numpy.arange(30) / 10.0 - 1.5
        # Make a 2-d array containing a function of x and y.  First create
        # xm and ym which contain the x and y values in a matrix form that
        # can be `broadcast' into a matrix of the appropriate shape:
        xm = x[:, numpy.newaxis]
        ym = y[numpy.newaxis, :]
        m = (numpy.sin(xm) + 0.1 * xm) - ym**2
        wait('a function of two variables from a GridData file')
        g('set parametric')
        g('set data style lines')
        g('set hidden')
        g('set contour base')
        g.xlabel('x')
        g.ylabel('y')
        g.splot(Gnuplot.GridData(m, x, y, binary=0, inline=0))
        wait('Same thing, saved to a file')
        Gnuplot.GridData(m, x, y, binary=0, inline=0, filename=filename1)
        g.splot(Gnuplot.File(filename1, binary=0))
        wait('Same thing, inline data')
        g.splot(Gnuplot.GridData(m, x, y, binary=0, inline=1))

        wait('The same thing using binary mode')
        g.splot(Gnuplot.GridData(m, x, y, binary=1))
        wait('Same thing, using binary mode and an intermediate file')
        Gnuplot.GridData(m, x, y, binary=1, filename=filename1)
        g.splot(Gnuplot.File(filename1, binary=1))

        wait('The same thing using compute_GridData to tabulate function')
        g.splot(
            Gnuplot.funcutils.compute_GridData(
                x,
                y,
                lambda x, y: math.sin(x) + 0.1 * x - y**2,
            ))
        wait('Same thing, with an intermediate file')
        Gnuplot.funcutils.compute_GridData(
            x,
            y,
            lambda x, y: math.sin(x) + 0.1 * x - y**2,
            filename=filename1)
        g.splot(Gnuplot.File(filename1, binary=1))

        wait('Use compute_GridData in ufunc and binary mode')
        g.splot(
            Gnuplot.funcutils.compute_GridData(
                x,
                y,
                lambda x, y: numpy.sin(x) + 0.1 * x - y**2,
                ufunc=1,
                binary=1,
            ))
        wait('Same thing, with an intermediate file')
        Gnuplot.funcutils.compute_GridData(
            x,
            y,
            lambda x, y: numpy.sin(x) + 0.1 * x - y**2,
            ufunc=1,
            binary=1,
            filename=filename1)
        g.splot(Gnuplot.File(filename1, binary=1))

        wait('And now rotate it a bit')
        for view in range(35, 70, 5):
            g('set view 60, %d' % view)
            g.replot()
            time.sleep(1.0)

        wait(prompt='Press return to end the test.\n')
    finally:
        os.unlink(filename1)
        os.unlink(filename2)
コード例 #11
0
def ratioPlotter():
    # For a particular benchmark, plots the ratio of time per rep
    # of to a base file against the data size.
    # The base file is (usually) the file containing data for
    # the 1 OpenMP thread per MPI process benchmark run.
    global gplotter

    #Find the output file name
    print("Enter file name for hardcopy of plot...")
    outFileName = sys.stdin.readline()
    #setup file name
    outFormat = ".eps"
    outFormat = outFormat.rstrip('\n')
    outFileName = outFileName.rstrip('\n') + outFormat

    #gplotter = Gnuplot.Gnuplot()
    #Clear the gunplot object
    gplotter.clear()

    #Setup axis labels in plot
    gplotter('set border')
    gplotter.xlabel('Message Size (bytes)')
    gplotter.ylabel('Ratio')
    #Use a logscale along x axis..
    gplotter('set logscale x')
    # ..and format of numbers along x axis is 10^
    gplotter('set format x "10^{%L}"')

    #Uncomment next two lines for log scale along y axis
    #gplotter('set logscale y')
    #gplotter('set format y "10^{%L}"')

    #Setup legend
    gplotter('set key spacing 1.5')  #gap between legend entries
    gplotter('set key height 2')  #gap b/w top/bottom legend & frame
    gplotter('set key width 2')  #gap b/w left/right legend & frame
    gplotter('set key box')  #turn on frame around key
    #Line below sets position of the key in the plot - change this for different position
    gplotter('set key top left')

    #Start reading in names of data from base file
    #1) Read the name of base file.
    print "Enter name of the file to be used as the divisor (output for 1 OpenMP thread per MPI Process).."
    str = sys.stdin.readline()
    baseDataFileName = str.rstrip('\n')  #remove newline from end
    #2) Open the base file
    baseFileHandle = open(baseDataFileName, 'r')

    #3) Initialise the base file message size and time lists...
    baseFileMsgSize = []
    baseFileTime = []

    #4) Read data from baseFile
    str = baseFileHandle.readline()
    while (str != ''):  # while not EOF
        str = str.lstrip()  # Remove whitespace from start of line
        if (not str.startswith('#')):  # Check if line is a comment
            file1str = str.split()  # Split line at whitespaces
            baseFileMsgSize.append(file1str[0])  # Add to message size list ..
            baseFileTime.append(file1str[1])  # ...and to time per rep list
        str = baseFileHandle.readline()  # Read next line
    #Close base file after reading
    baseFileHandle.close()

    #Reading data from other files
    while (True):
        #Read file name
        print "Enter the name of file to get the ratio of, 0 to exit"
        ratioFileName = sys.stdin.readline()
        #Remove \n from fileName
        ratioFileName = ratioFileName.rstrip('\n')
        if (ratioFileName == '0'):  #if user eneteed a '0'
            #exit out of loop
            break
        else:
            #Open the file
            ratioFileHandle = open(ratioFileName, 'r')

            #Initialise the ratio file message size and time lists...
            ratioListMsgSize = []
            ratioListTime = []

            #Need counter so that only get ratio for same message sizes...
            #..initialise msgSizePosCounter to 0.
            msgSizePosCounter = 0
            #Start reading the file
            line = ratioFileHandle.readline()
            while (line != ''):  #while not EOF
                line = line.lstrip()  #remove whitespaces from start of line
                if (not line.startswith('#')):  #if not a comment
                    msgSizeReadComplete = False
                    lineSplit = line.split()  #split the line at whitespace
                    msgSize = lineSplit[
                        0]  #first element of line split is message size
                    #Now need to find if the same message size is in baseFileMsgSize list...
                    while (msgSizeReadComplete == False):
                        # ...if we've read more message sizes than length of baseFileMsgSize list
                        if (msgSizePosCounter > len(baseFileMsgSize) - 1):
                            # don't use that message size
                            msgSizeReadComplete = True
                        # ...if message size is equal baseFileMsgSize[msgSizePosCounter]
                        elif (int(msgSize) == int(
                                baseFileMsgSize[msgSizePosCounter])):
                            #keep mesaage size and find ratio
                            ratioListMsgSize.append(int(msgSize))
                            ratioListTime.append(
                                float(lineSplit[1]) /
                                float(baseFileTime[msgSizePosCounter]))
                            msgSizeReadComplete = True  # finsihed with this message size: go to next one.
                            msgSizePosCounter = msgSizePosCounter + 1
                        # ..if message size if greater than baseFileMsgSize[msgSizePosCounter]
                        elif (int(msgSize) > int(
                                baseFileMsgSize[msgSizePosCounter])):
                            #move to next element in baseFileMsgSize list
                            msgSizePosCounter = msgSizePosCounter + 1
                            msgSizeReadComplete = False
                        # ...if message size if less than baseFileMsgSize[msgSizePosCounter]
                        elif (int(msgSize) < int(
                                baseFileMsgSize[msgSizePosCounter])):
                            #this message file doesn't exist in baseFileMsgSize list: read to next line
                            msgSizeReadComplete = True
                #Read the next line from the file and loop again
                line = ratioFileHandle.readline()
            #When finished reading file, close it.
            ratioFileHandle.close()

            #Now plot the ratios...
            #First need to convert the lists to numpy arrays
            ratioArrayMsgSize = numpy.array(ratioListMsgSize)
            ratioArrayTime = numpy.array(ratioListTime)

            #Find title for the plot
            splitName = ratioFileName.split('_')  #Split at '_'
            procs = splitName[1].rstrip(
                'MPIProcs')  #Find number of MPI Procs (2nd element)
            threads = splitName[2].rstrip(
                'Threads.dat')  #and number of threads (3rd element)
            t = threads + ' Threads, ' + procs + ' Processes'  #create title

            #Plot the data
            gplotter.replot(
                Gnuplot.Data(ratioArrayMsgSize,
                             ratioArrayTime,
                             with_='linespoints',
                             title=t))
            print "\"", t, "\"", "plotted"

    gplotter('set xrange[1:100000000] writeback')
    #Plot line along y=1 to represent 1 OpenMP thread per MPI process
    gplotter.replot(Gnuplot.Func('1', with_='lines lt -1', title=None))
    #Write hardcopy
    print 'Hardcopy written to:', outFileName
    gplotter.hardcopy(outFileName, eps=1, color=1, enhanced=1)
    gplotter.close()
    #change yellow lines to brown
    command = "sed -i 's/^LT5/LT7/g' " + outFileName
    os.system(command)
コード例 #12
0
import Gnuplot, math
import time



def f(x):
    return (11*x - 6)*(2*x - 3)

gp = Gnuplot.Gnuplot(debug=0)

x = arange(10, dtype='float_')
y = x**2

# save plots for displaying later
plot1 = Gnuplot.Data(x, y, title='squares', with_='points 3 3')
plot2 = Gnuplot.Func('x**2', title='calculated by gnuplot')

# Plot
gp.title('The function x**2')
gp.xlabel('x')
gp.ylabel('x**2')

min = -1000
max = +1000

# keep replotting graph to animate
for i in range(min, max):
    x = i
    y = f(x)
    plot1 = Gnuplot.Data([min,x,max], [0,y,f(max)], with_='points 1 3')
    gp.plot(plot1)
コード例 #13
0
ファイル: gnuplot_data.py プロジェクト: logust79/cgat-apps
        g.xlabel(legend[0])

        for x in range(1, len(legend)):

            g.replot(
                Gnuplot.Data(data,
                             cols=(0, x),
                             xwith=param_with,
                             title=legend[x]))

            if param_fit:
                g.replot(Fit(data, cols=(0, x)))

        if param_function:
            for f in param_function:
                g.replot(Gnuplot.Func(f))

    g.refresh()

    if param_hardcopy:
        g.hardcopy(param_hardcopy, terminal=param_terminal)

##         g.replot( Gnuplot.File( fn1,
##                                 using="1:2",
##                                 with = param_with,
##                                 title=legend[x]) )
#        print d.filename

##         temps += PlotFit( g, data, cols=(0, x) )

#    print d.filename
コード例 #14
0
#!/usr/bin/env python
import Gnuplot

gp = Gnuplot.Gnuplot()
gp('set title "sin(x) and cos(x)"')
gp('set terminal png size 2560,1600')
gp('set xlabel "x-axis: from -2*pi to +2*pi"')
gp('set ylabel "y-axis: from -1 to +1"')
gp('set terminal png')
gp('set output "sincos.png"')
gp('set xrange [-2*pi:2*pi]')
gp('set xtics ("0" 0,"-270" -(3/2)*pi, "-180" -pi, "-90" -pi/2, "90" pi/2, "180" pi, "270" (3/2)*pi)'
   )
gp('set ytics ("0" 0, "0.5" 0.5, "1" 1, "-0.5" -0.5, "-1" -1)')
gp('set grid')
gf = Gnuplot.Func('sin(x), cos(x)')
gp.plot(gf)
コード例 #15
0
ファイル: test.py プロジェクト: vishalbelsare/ompc
        f.close()

        print '############### test Func ###################################'
        wait('Plot a gnuplot-generated function')
        g.plot(Gnuplot.Func('sin(x)'))

        wait('Set title and axis labels and try replot()')
        g.title('Title')
        g.xlabel('x')
        g.ylabel('y')
        g.replot()

        wait('Style linespoints')
        g.plot(Gnuplot.Func('sin(x)', with='linespoints'))
        wait('title=None')
        g.plot(Gnuplot.Func('sin(x)', title=None))
        wait('title="Sine of x"')
        g.plot(Gnuplot.Func('sin(x)', title='Sine of x'))
        wait('axes=x2y2')
        g.plot(Gnuplot.Func('sin(x)', axes='x2y2', title='Sine of x'))

        print 'Change Func attributes after construction:'
        f = Gnuplot.Func('sin(x)')
        wait('Original')
        g.plot(f)
        wait('Style linespoints')
        f.set_option(with='linespoints')
        g.plot(f)
        wait('title=None')
        f.set_option(title=None)
        g.plot(f)
コード例 #16
0
ファイル: demo.py プロジェクト: vishalbelsare/ompc
    # Plot one dataset from an array and one via a gnuplot function;
    # also demonstrate the use of item-specific options:
    x = arange(10, typecode=Float)
    y1 = x**2
    # Notice how this plotitem is created here but used later?  This
    # is convenient if the same dataset has to be plotted multiple
    # times.  It is also more efficient because the data need only be
    # written to a temporary file once.
    d = Gnuplot.Data(x, y1,
                     title='calculated by python',
                     with='points 3 3')
    g.title('Data can be computed by python or gnuplot')
    g.xlabel('x')
    g.ylabel('x squared')
    # Plot a function alongside the Data PlotItem defined above:
    g.plot(Gnuplot.Func('x**2', title='calculated by gnuplot'), d)
    raw_input('Please press return to continue...\n')

    # Save what we just plotted as a color postscript file.

    # With the enhanced postscript option, it is possible to show `x
    # squared' with a superscript (plus much, much more; see `help set
    # term postscript' in the gnuplot docs).  If your gnuplot doesn't
    # support enhanced mode, set `enhanced=0' below.
    g.ylabel('x^2') # take advantage of enhanced postscript mode
    g.hardcopy('gp_test.ps', enhanced=1, color=1)
    print ('\n******** Saved plot to postscript file "gp_test.ps" ********\n')
    raw_input('Please press return to continue...\n')

    g.reset()
    # Demonstrate a 3-d plot:
コード例 #17
0
    G = Gnuplot.Gnuplot(debug=0)
except: G = None

def wait_for_input():
    raw_input("press enter to exit graph")

def plot_bananas(pts1, pts2, filename, m=None, b=0, title='', \
    x_label='', y_label='', x_range=(1,100), y_range=(1,100), output=None):
    """plot a line and a set of points
    
    TODO: extend to arbitrary amt of sets of points **pts"""
    if(G):
        G.reset()
        p1 = Gnuplot.Data(pts1, title="apples", with="points 1 2")
        p2 = Gnuplot.Data(pts2, title="bananas", with="points 3")
        if m: line = Gnuplot.Func ('%f + (%f) * x' % (b, m))
        G.title("apples and bananas")
        G.xlabel("size")
        G.ylabel("yellowness")
        G.set_range('xrange', (0,100))
        G.set_range('yrange', (0,100))
        if m: G.plot(line, p1, p2)
        else: G.plot(p1, p2)
        G.hardcopy(filename, terminal='png')
        wait_for_input()

def plot_line(m, b, xrange=None, yrange=None):
    """plot a line with slope m and bias b, currently using Gnuplot"""
    if(G):
        line = Gnuplot.Func ('%f + (%f) * x' % (b, m))
        if xrange: G.set_range('xrange', xrange)
コード例 #18
0
############################################################
#
#    plotting styles
#
############################################################

from numpy import *
import Gnuplot
import math



gp = Gnuplot.Gnuplot(debug=1)

x = arange(10, dtype='float_')
y = x**2

# save plots for displaying later
plot1 = Gnuplot.Func('x**2/100.', title='x**2', with_='boxes')
plot2 = Gnuplot.Func('cos(x)', title='cos(x)', with_='lines')
plot3 = Gnuplot.Func('norm(x)', title='norm(x)', with_='errorbars')

# Plot
gp.title('Various functions and styles')
gp.xlabel('x')
gp.ylabel('y')
gp.plot(plot1, plot2, plot3)


1
コード例 #19
0
ファイル: xx.py プロジェクト: baijian/pygnuplot
#!/usr/bin/env python
import Gnuplot

gp = Gnuplot.Gnuplot()
gp('set title "x^2 and 1/x^2"')
gp('set xlabel "x-axis: from -10 to +10"')
gp('set ylabel "y-axis: from 0 to 100"')
gp('set terminal png')
gp('set terminal png size 1280,800')
gp('set output "xx.png"')
gp('set xrange [-10:10]')
gf = Gnuplot.Func('x*x, 1/(x*x) with filledcurves fs')
gp.plot(gf)

コード例 #20
0
def rotation():
    """Demonstrate the Gnuplot package."""
    # Create arrays of points
    xCorrection = [0, 1, 2, 3, 4, 5]
    yCorrection = [1.1, 3, 7.5, 8, 1, 2]
    # A straightforward use of gnuplot.  The `debug=1' switch is used
    # in these examples so that the commands that are sent to gnuplot
    # are also output on stderr.
    g = Gnuplot.Gnuplot(debug=1)
    g('set multiplot')
    g('set data style points')  # give gnuplot an arbitrary command
    # Plot a list of (x, y) pairs (tuples or a numpy array would
    # also be OK):
    for i in range(0, 5):
        g.plot([xCorrection[i], yCorrection[i]])

    g.title('Rotation')  # (optional)
    raw_input('Please press return to continue...\n')

    g.reset()
    # Plot one dataset from an array and one via a gnuplot function;
    # also demonstrate the use of item-specific options:
    x = arange(10, dtype='float_')
    y1 = x**2
    # Notice how this plotitem is created here but used later?  This
    # is convenient if the same dataset has to be plotted multiple
    # times.  It is also more efficient because the data need only be
    # written to a temporary file once.
    d = Gnuplot.Data(x, y1, title='calculated by python', with_='points 3 3')
    g.title('Data can be computed by python or gnuplot')
    g.xlabel('x')
    g.ylabel('x squared')
    # Plot a function alongside the Data PlotItem defined above:
    g.plot(Gnuplot.Func('x**2', title='calculated by gnuplot'), d)
    raw_input('Please press return to continue...\n')

    # Save what we just plotted as a color postscript file.

    # With the enhanced postscript option, it is possible to show `x
    # squared' with a superscript (plus much, much more; see `help set
    # term postscript' in the gnuplot docs).  If your gnuplot doesn't
    # support enhanced mode, set `enhanced=0' below.
    g.ylabel('x^2')  # take advantage of enhanced postscript mode
    g.hardcopy('gp_test.ps', enhanced=1, color=1)
    print('\n******** Saved plot to postscript file "gp_test.ps" ********\n')
    raw_input('Please press return to continue...\n')

    g.reset()
    # Demonstrate a 3-d plot:
    # set up x and y values at which the function will be tabulated:
    x = arange(35) / 2.0
    y = arange(30) / 10.0 - 1.5
    # Make a 2-d array containing a function of x and y.  First create
    # xm and ym which contain the x and y values in a matrix form that
    # can be `broadcast' into a matrix of the appropriate shape:
    xm = x[:, newaxis]
    ym = y[newaxis, :]
    m = (sin(xm) + 0.1 * xm) - ym**2
    g('set parametric')
    g('set data style lines')
    g('set hidden')
    g('set contour base')
    g.title('An example of a surface plot')
    g.xlabel('x')
    g.ylabel('y')
    # The `binary=1' option would cause communication with gnuplot to
    # be in binary format, which is considerably faster and uses less
    # disk space.  (This only works with the splot command due to
    # limitations of gnuplot.)  `binary=1' is the default, but here we
    # disable binary because older versions of gnuplot don't allow
    # binary data.  Change this to `binary=1' (or omit the binary
    # option) to get the advantage of binary format.
    g.splot(Gnuplot.GridData(m, x, y, binary=0))
    raw_input('Please press return to continue...\n')

    # plot another function, but letting GridFunc tabulate its values
    # automatically.  f could also be a lambda or a global function:
    def f(x, y):
        return 1.0 / (1 + 0.01 * x**2 + 0.5 * y**2)

    g.splot(Gnuplot.funcutils.compute_GridData(x, y, f, binary=0))
    raw_input('Please press return to continue...\n')
コード例 #21
0
ファイル: svm.py プロジェクト: vegetablepig/python
    else:
        print "error"
        
class0 = np.array(class0)
class1 = np.array(class1)

func = "(-1)*" \
       + "("+ str(A) +")" \
       + "/" \
       + "("+str(B)+")" \
       + "*x+" \
       + "(-1)*" \
       + "("+str(C)+")" \
       + "/" + "("+str(B)+")"

print func

#if __name__ == "__main__":
    
g = Gnuplot.Gnuplot(debug=1)
g.title('SVM') # (optional)
g('set data style linespoints')

d0 = Gnuplot.Data(class0, title = "Class 0")
d1 = Gnuplot.Data(class1, title = "Class 1")
d2 = Gnuplot.Func(func, title = "Separating Plane")

g.plot(d0, d1, d2)

raw_input()