Free since 2005 · No login required
AT

Academic Tutorials

Learn at your own pace

site-mobile-top-banner · 320x50

Processing the Data for Gnuplot

Added 30 Jul 2008

In order to generate an image, we must turn the data into something that Gnuplot can understand. Gnuplot wants the data in the following format:
x0 y0 z(0, 0)
x1 y0 z(1, 0)
x2 y0 z(2, 0)
...
xN y0 z(N, 0)

x0 y1 z(0, 1)
x1 y1 z(1, 1)
x2 y1 z(2, 1)
...
xN y1 z(N, 1)

...

x0 yN z(0, N)
x1 yN z(1, N)
x2 yN z(2, N)
...
xN yN z(N, N)

This is each coordinate (x, y, z) on a separate line, with every 'row' (new y coordinate) separated with an extra newline.

This is produced from the data in the worksheet, using the GenerateGnuplotData function in the plot module:

def GenerateGnuplotData(sheet):
    out = []
    for y in range(1, sheet.MaxRow + 1):
        row = []
        for x in range(1, sheet.MaxCol + 1):
            value = sheet[x, y]
            u = (6.0 / 50) * x - 3
            v = (6.0 / 50) * y - 3
            row.append('%s %s %s' % (u, v, value))
        out.append(row)
    return '\n\n    '.join('\n    '.join(row) for row in out)