Tag Archives: gnuplot

Render 2d points with gnuplot to PNG

One of the easiest way to render some points with gnuplot is:

  1. write to file (eg points.txt) the points you want to render in simple text format, one line per point (x,y pairs, no tabs no commas etc)
  2. create a script with the code shown below (eg graph.gnuplot)
  3. run the script with gnuplot (eg gnuplot graph.gnuplot)
  4. Open the png file with a program of your choice.

point file sample:

10 10
20 20
30 30


script sample

set terminal png
set size ratio -1
set output "./graph.png"
plot \
"points1.txt" notitle with points pointsize 0.5 linecolor rgb "green",\
"points2.txt" notitle with points pointsize 0.5 linecolor rgb "yellow",\
"points3.txt" notitle with points pointsize 0.5 linecolor rgb "black"


execution example:

gnuplot graph.gnuplot

Terminal PNG not found in gnuplot

In some linux destributions, the default version of gnuplot does not always include PNG support.

Here it the easiest way to fix this:

  1. Download gnuplot from https://sourceforge.net/projects/gnuplot/
  2. Untar to a directory of your choice
  3. Open terminal at that directory
  4. Run the following commands:
    1. sudo apt-get install libgd2-dev
    2. ./configure
    3. make
    4. make check
    5. sudo make install

That’s it.

You can find code examples for PNG terminal here:

http://gnuplot.sourceforge.net/demo_5.0/

You can read more gnuplot terminals here:

http://www.gnuplotting.org/output-terminals/