GNUPLOT

USEFUL LINKS

#not so Frequently Asked Questions
not so Frequently Asked Questions
Gnuplot: An Interactive Plotting Program
Using Random Function


COMMANDS

ANIMATED GIF

or making movie with gnuplot

set terminal gif animate delay 10
set output "animate.gif"
splot sin(5*x/10)*cos(5*y/10)
splot sin(6*x/10)*cos(6*y/10)
splot sin(7*x/10)*cos(7*y/10)
splot sin(8*x/10)*cos(8*y/10)

using background image for plots

 plot "PMF.png" binary  filetype=png w rgbimage

set MARGIN

When the margins are defined explicitly, the size of graph does not change even formats of the X and Y tics are changed.
This is especially in MULTIPLOT.

 set bmargin {<margin>}
 set lmargin {<margin>}
 set rmargin {<margin>}
 set tmargin {<margin>}
 show margin

or explicitly
set lmargin at screen 0.10
set rmargin at screen 0.20

MULTIPLOT

Gnuplot can plot more than one figure in a frame (like subplot in matlab ) i.e., try:

set output 'R_L_fe_sum.out.eps'
set terminal postscript color solid eps enhanced
set xlabel 'simulation time (ns)'
set ylabel 'free energy(kcal/mol)'
set multiplot;
set size 1,0.5;
set title 'Final Forward free energy'
set origin 0.0,0.5;
set label  "A"  at screen 0.05, screen 0.95 font "Helvetica,20" 
 plot 'r_fe_sum.out'   usin ($0/500):1 title '{/Symbol D}+PHS, Unrestrained' w l lw 6,'MC_r_fe_sum.out'   usin ($0/500):1 title 'Reference compound' w l lw 6
 set title 'Final Backward free energy'
set label  "B" at screen 0.05, screen 0.45 font "Helvetica,20"
set origin 0.0,0.0; plot 'l_fe_sum.out'   usin ($0/500):1 title '{/Symbol D}+PHS; Unrestrained' w l lw 6, 'MC_l_fe_sum.out'   usin ($0/500):1 title 'Reference compound' w l lw 6
unset multiplot
set out
reset

set LABEL size,position etc.

set label  "B" at screen 0.05, screen 0.45 font "Helvetica,20"
set xtic font "Helvetica,8.5"; set ytic font "Helvetica,8.5" 
set key at screen 0.95 ,screen 0.25 font "Times,8.5"
set key spacing 4

Set LINE STYLE

set style line 1 lt rgb "blue" lw 5
set style line 2 lt rgb "magenta" lw 5

plot 'data_file1' usin 1:2:3 w yerrorbar   ls 1 title ' data1 ', 'data_file2' usin 1:2:3 w yerrorbar   ls 2 title ' data2 '

Set Errorbar Styles

set terminal pngcairo  transparent enhanced
set output 'error_bar_style.png'
set key font 'Helvetica,10'
set tics font 'Helvetica,10'
set yrange [-0.001:0.1]
set style line 1 lc rgb 'red' lt 1 lw 1 
set style line 2 lc rgb 'green' lt 2 lw 1.1 pt 1
set style line 3 lc rgb 'orange' lt 3 lw 1.2 pt 2
set style line 4 lc rgb 'blue' lt 3 lw 1.3 pt 3
set style line 5 lc rgb 'violet' lt 3 lw 1.4 pt 4
set style line 6 lc rgb 'magenta' lt 3 lw 1.4 pt 6

plot 'ammonium/KL_non_opt_Mean_SD.out' usi (($0+1)*2):($1+0.01):3  w yerrorbars ls 1  title 'style line 1' , 'ammonium/KL_non_opt_Mean_SD.out' usi (($0+1)*2):($1+0.02):3  w yerrorbars ls 2  title 'style line 2','ammonium/KL_non_opt_Mean_SD.out' usi (($0+1)*2):($1+0.03):3  w yerrorbars ls 3  title 'style line 3','ammonium/KL_non_opt_Mean_SD.out' usi (($0+1)*2):($1+0.04):3  w yerrorbars ls 4  title 'style line 4','ammonium/KL_non_opt_Mean_SD.out' usi (($0+1)*2):($1+0.05):3  w yerrorbars ls 5  title 'style line 5','ammonium/KL_non_opt_Mean_SD.out' usi (($0+1)*2):($1+0.06):3  w yerrorbars ls 6  title 'style line 6'

error_bar_style.png

using shell commands in plot

plot "< awk '{print $1}' data.out" using 1:3

drawing arrows

set arrow xval1,yval1 to xval2,yval2

Using variable file name

filenames = "first second third fourth fifth"
plot for [file in filenames] file."dat" using 1:2 with lines
#or
filename(n) = sprintf("file_%d", n)
plot for [i=1:10] filename(i) using 1:2 with lines

Using non-numeric value for x-axis

## for exampl using  coloumn 1 values for x axis

plot "out.dat" using ($0):2:xtic(1)
[[/code]]

HANDY SCRIPTS for GNUPLOT

a simple script

set terminal postscript color solid eps enhanced
set output 'ADFDA_AS4.eps'
set xlabel 'pH' font 'bold,20'
set ylabel 'Deprotonation Fraction' font 'bold,20'
#set title 'Deprotonation_AS4_2'
f(x) = 1-x
set key bottom right
plot 'phex_result_AS4_2' using 1:(f($10)) w linespoints lw 5 title 'ASP2 pHRE','phex_result_AS4_4' using 1:(f($10)) w linespoints lw 5  title 'ASP4 pHRE','cph_result_AS4_2' using 1:(f($10)) w linespoints lw 5  title 'ASP2 CpH MD','cph_result_AS4_4' using 1:(f($10)) w linespoints lw 5  title 'ASP4 CpH MD', 'mod_com_result_AS4_2' using 1:(f($10)) w linespoints lw 5  title 'ASP reference'
set out
reset

curve fitting

and also showing the fitting results on the graph

set terminal postscript color solid eps enhanced
set output 'HH_AS4_4.eps'
set xrange [0:5]
set xlabel 'PH'
set ylabel 'log_{10} ([A^- ]/[AH])'
set title 'Hill_AS4_4'
g(x) = log10((1-x)/x)
h(x) = a*x+b
a = 1.00 ; b = -3.0 
fit h(x) 'result_AS4_4' using 1:(g($10)) via a, b
set label "pka=%6.1f" , -b/a at graph 0.5, graph 0.4 
plot 'result_AS4_4' using 1:(g($10)) w points, h(x) lw 5 title 'HH fit result' 
set out

animation of a classic particle in a double well potential

set terminal gif animate delay 10
set output "simulator.gif"
set style fill solid 1.0 border -1
set xrange [-2:2]
set xlabel "Reaction Coordinate"
set ylabel "Free Energy"
set style line 1 lt 2 lw 1 pt 3 ps 3
set style line 2 lt 1 lw 4 pt 3 ps 3
unset key
set format ''
set tics scale 0
t1=50
t2=10
t3=7
f(x)= sin(2*x)+1.5*cos(3*x)  # well 
do for [j=0:3]{

do for  [i=0:t1]{
set print "random.tmp"
t=-1+(0.3)*rand(0)
print sprintf("%8.5g %8.5g", t, f(t)+0.15)
unset print
plot f(x) ls 2 ,"random.tmp" with circles ls 1 title ''
}
###
do for  [i=0:t2]{
set print "random.tmp"
t=-1.5+(0.8)*rand(0)
print sprintf("%8.5g %8.5g", t, f(t)+0.15)
unset print
plot f(x) ls 2 ,"random.tmp" with circles ls 1 title ''
}
###
do for  [i=0:t1]{
set print "random.tmp"
t=-1+(0.3)*rand(0)
print sprintf("%8.5g %8.5g", t, f(t)+0.15)
unset print
plot f(x) ls 2 ,"random.tmp" with circles ls 1 title ''
}
}#end of first bigloop
###
do for  [i=0:t2]{
set print "random.tmp"
t=-0.5+(0.8)*rand(0)
print sprintf("%8.5g %8.5g", t, f(t)+0.20)
unset print
plot f(x) ls 2 ,"random.tmp" with circles ls 1 title ''
}
##
do for  [i=0:t3]{
set print "random.tmp"
t=-0.1+(0.4)*rand(0)
print sprintf("%8.5g %8.5g", t, f(t)+0.20)
unset print
plot f(x) ls 2 ,"random.tmp" with circles ls 1 title ''
}
##
do for  [i=0:t2]{
set print "random.tmp"
t=0.2+(0.5)*rand(0)
print sprintf("%8.5g %8.5g", t, f(t)+0.20)
unset print
plot f(x) ls 2 ,"random.tmp" with circles ls 1 title ''
}
##
do for  [i=0:t3]{
set print "random.tmp"
t=0.8+(0.4)*rand(0)
print sprintf("%8.5g %8.5g", t, f(t)+0.20)
unset print
plot f(x) ls 2 ,"random.tmp" with circles ls 1 title ''
}
##
do for  [i=0:t2]{
set print "random.tmp"
t=0.2+(0.5)*rand(0)
print sprintf("%8.5g %8.5g", t, f(t)+0.20)
unset print
plot f(x) ls 2 ,"random.tmp" with circles ls 1 title ''
}
##
do for  [i=0:t3]{
set print "random.tmp"
t=-0.1+(0.4)*rand(0)
print sprintf("%8.5g %8.5g", t, f(t)+0.20)
unset print
plot f(x) ls 2 ,"random.tmp" with circles ls 1 title ''
}
##
do for  [i=0:t2]{
set print "random.tmp"
t=-0.5+(0.8)*rand(0)
print sprintf("%8.5g %8.5g", t, f(t)+0.20)
unset print
plot f(x) ls 2 ,"random.tmp" with circles ls 1 title ''
}
##

set out

MD_potential_well.gif
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License