Creating High Quality Plots Using GNUplot

GNUplot is the standard mathematical plotting tool in Unix systems, it runs now on Linux, MS windows, OS2 and Mac, I used gnuplot for plotting simulation results for my thesis, it has a lot of features and its website has very useful demos.

One of it’s greatest feature is pallete mapped colored 3D plots, in simple words if you want to draw 3D plot on 2D plot and presenting the 3rd variable as color that’s what palette mapped 3D plot mean.

An example i made,  i want to show the bunching of beam particles, so i plot the beam in x-z plane, and show energy of the beam represented as color (red maps to high energy particles and blue maps to low energy particles) as seen in image.

Particle Beam energy - Bunch Creation
Particle Beam energy - Bunch Creation


In this image we see that the particles coming from left is speeding up (High energy – red)and the electrons at the right is slowing down (Low energy – blue) creating what is called a bunch in the middle.

Here is .gnu file used as input to gnuplot to generate this plot. it’s simple small and talking about itself. The data file for this plot is even simple it’s comma seperated dat file has the 3 values (x,z, energy)for each point in a line.

# Created by: Yasser Nour
# Date: 04/04/2009
# Released to the public domain with no warranty of any kind
#

reset

# Output to png file
set terminal png small x000000 \
xffffff x404040 xff0000 xffa500 x66cdaa \
xcdb5cd xadd8e6 x0000ff xdda0dd x9500d3
set output “beam_energy.png”

set style line 1

# Set aspect ration of the graph
set size 1.25, 1.25

# Set origin of the graph
set origin 0.0, 0.0

# Set grids on graphs
set grid

set pm3d map
#set palette rgbformulae 33,13,10
set palette rgbformulae 22,13,-31

set cbrange [1.07:1.11]
set cbtics (“1.07” 1.07, “1.08” 1.08, “1.09” 1.09, “1.10” 1.10, “1.11” 1.11)

# Set title of first graph, and labels
set title “Output Beam (X vs. Z with Gamma Value as Color)”
set xlabel “Z (m)”
set ylabel “X (m)”

# Set Plot ranges x-range, y-range
set autoscale x
set yrange [-0.04:0.04]

# Plot from File
splot ‘beam3D.txt’ with points pointtype 0 palette

There is other remarkable features in GNUplot that i will post about them in future ISA. Enjoy free tools.

Leave a comment