Posted on | February 27, 2008 | 12 Comments
Working in CFD, I often have to create contours plots starting from rough data in a text file generated by in house codes. This can be easily accomplished using gnuplot. Here you can see a simple example of what you can do.
Being an openSUSE user, I will explain how to install gnuplot on this distribution, but the instructions to generate contours plots are absolutely general.
- The installation of gnuplot on openSUSE 10.3 is straightforward. Just use the 1-click install link available here, and follow the procedure shown by the installer.
- Gnuplot requires the data to be saved in a text file organized in one of the two following ways:
- One set of 3 coordinates (x y z) per line, with line breaks separating the data, and an empty line to separate the rows of the matrix of data.
- One single value (z) per line, with line breaks separating data, and an empty line to separate the rows of the matrix of data. For example, if you have a 3×2 matrix of data, the corresponding file will be:
—- empty line —-
—- empty line —-
- Once the data to plot are prepared in that format, which can be easily implemented in all computational codes, just start gnuplot in a terminal, typing gnuplot.
- The instruction to plot a simple contour plot are the following, assuming the data file is called data.dat:
- set size square -> It sets that the plot must be squared. Of course this is optional, and depends on the case.
- unset title -> It removes the title. You can use set title ‘text’ to set an appropriate title if you want.
- set pm3d map -> It configures gnuplot to generate contour plots.
- set xrange [0:100] and set yrange [0:100] -> They set the range of the plot. Change the interval according to your data.
- set format x “” and set format y “” -> They remove the numbers from the axes.
- set cbrange [0:1] -> It sets the range of the colorbar in the contour plot. Values out of range are coloured as the closest extreme value.
- set palette rgbformulae 22,13,10 -> It sets the colour palette. Please, see the reference for further information on this.
- splot ‘data.dat’
- At this point, gnuplot is set properly to plot your data. Just check the plot by showing it with: splot ‘data.dat’
- If the result is satisfactory, you can easily export it to an eps file, with the following commands:
- set term postscript enhanced color
- set output “data.eps”