Key features:
header/title on graph, arrays, loop over input files, loop over line colors, nested "for" loops, several graphs in same figure, dotted/dashed lines, vertical lines ("arrow"), several "plot" commands, major tick marks only, plot data from file, get data from different folder/directory, plot data from several files, plot data from several directories, shift input data, legend aligned with curves/data, all legend items in one column, Angstrom symbol
On this rare occasion, I've placed the image below the script, because the figure is extraordinarily tall.
In case you're interested, this figure is the pair radial distribution functions of a molecular crystal. (The sharpness of the curves stems from the fact that the RDFs are of a crystal instead of a liquid.) Since my molecular crystal had 14 unique atoms, there are (14)*(14+1)/2 = 105 combinatorial atom-atom pair RDFs to plot. I wanted to see all of them at once. To make matters worse, for every atom-atom RDF, there were 5 variant curves (RDFs) I needed to compare. So, I made this super-tall graph to exhaustively plot all the curves in one figure for easy comparison.
This figure was very useful to me for quickly visual analyzing my data. The figure has several useful features:
The spacing of items in the plot's legend, set key spacing 3.425, was heuristically tailored so that each row of the legend lies close to its corresponding curve.
At each ordinate tick mark ("shifted g(r)") there are actually 5 different curves plotted: 1 solid, colored line; 1 solid, grey line; and 3 dashed, colored lines. By using a different plot command for each of these 5 curves, I forced gnuplot to loop through its default colors, causing each bundle of 5 curves to use the same colors.
I used gnuplot lists/arrays to draw data from variable-named data files. For example, "AllProblems_all/rdf_".word(list_sel1, i)."-".word(list_sel2, j).".dat" uses two variables to find/loop over files named "rdf_*-*.dat".
Dashed/dotted lines are indicated by, e.g., dt ".". What is cool about the dt ("dash type") feature in gnuplot is that you can input your own pattern in the quotes! So dt "." creates a dotted line while dt "-." creates a dash-dot-dash-dot pattern, etc.
Vertical lines help you keep up with the abscissa scale even far away from the abscissa label (set xlabel "Atom pair distance (\305)") at the bottom of the graph.
reset # good idea to make sure you start "fresh"
set terminal pngcairo truecolor nocrop enhanced font "arial,40" size 2000,16120 # good ratio for publication: 1.336x1:: 3078,2303
set encoding iso_8859_1
set output "paracetamol_RDFs_EvalProblems_v3d.png" ## output filename
set multiplot layout 1,1 title "problems: grey | Cholesky: ... | EGrids: -.- | TotalE: --- | successes: solid" font "arial,35"
## SETTINGS FOR WHOLE PLOT
unset grid ## alternatively, use "with lines" after "plot"
set samples 10000 ## default=100... improves smoothness
set border 15 lw 6
set tics scale 1.25
set bars 0.5 ## errorbar cap width {small | large | fullwidth | <size>}
#set lmargin 5
#set lmargin at screen 0.175
#set bmargin at screen 0.175
#set pointsize 3
## SETTINGS FOR HORIZONTAL AXIS=ABSCISSA
set xlabel "Atom pair distance (\305)" offset 0,.5
set xrange [.5:7] ## options: "[min:max]" , "[:]" is "perfect" range,
#set format x "%1.1f" ## "%N.Mf" has N total digits, with M after the decimal.
set xtics -10,1,10 offset -.25,.25 #out nomirror ## this is the spacing between tics on the x-axis
set mxtics 2 ## frequency of the MINOR x-tics;
## SETTINGS FOR VERTICAL AXIS=ORDINATE
set ylabel "shifted g(r)" offset 1,0 ## vertical, ordinate label
set yrange [.9:106.5] ## options: "[min:max]" , "[:]" is "perfect" range,
#set format y "%1.1f" ## "%N.Mf" has N total digits, with M after the decimal.
set ytics -10,1,150 offset .25,0 #nomirror ## spacing between tics on the y-axis
#set mytics 0 ## frequency of the MINOR x-tics;
## SETTINGS FOR KEY/LEGEND
set key spacing 3.425 ## vertical spacing between legend lines.
set key samplen .5 ## length of line sample shown in legend.
set key maxrows 200
set key maxcolumns 1
set key nobox
set key at graph .95,.995 ## where to put legend: left right center top bottom center
#set key left top
set key font "arial,30"
list_sel1 = "C1 C2 O3 N4 C5 C6 C7 C8 O9 H10 H11 H12 H13 H14"
list_sel2 = "C1 C2 O3 N4 C5 C6 C7 C8 O9 H10 H11 H12 H13 H14"
set arrow from 1.0,.9 to 1.0,106.5 nohead lw 1
set arrow from 2.0,.9 to 2.0,106.5 nohead lw 1
set arrow from 3.0,.9 to 3.0,106.5 nohead lw 1
set arrow from 4.0,.9 to 4.0,106.5 nohead lw 1
set arrow from 5.0,.9 to 5.0,106.5 nohead lw 1
set arrow from 6.0,.9 to 6.0,106.5 nohead lw 1
#set label "bin width = .1 (\305)" at 8,35 font "arial,80"
#dimer_Cm-Hw dimer_Cm-Ow dimer_Hm-Hw dimer_Hm-Ow
#set label "vs dimer Cm-Hw" at graph .05,.9
count = 106
plot for [i=1:words(list_sel1)] \
for [j=i:words(list_sel2)] \
count = count-1 \
"AllProblems_all/rdf_".word(list_sel1, i)."-".word(list_sel2, j).".dat" u 1:(2*$2+count) w lines lw 6 lc rgb "dark-grey" title "",\
count = 106
plot for [i=1:words(list_sel1)] \
for [j=i:words(list_sel2)] \
count = count-1 \
"Cholesky_all/rdf_".word(list_sel1, i)."-".word(list_sel2, j).".dat" u 1:(2*$2+count) w lines dt "." lw 4 title "",\
count = 106
plot for [i=1:words(list_sel1)] \
for [j=i:words(list_sel2)] \
count = count-1 \
"EGrids_all/rdf_".word(list_sel1, i)."-".word(list_sel2, j).".dat" u 1:(2*$2+count) w lines dt "-. " lw 2 title "",\
count = 106
plot for [i=1:words(list_sel1)] \
for [j=i:words(list_sel2)] \
count = count-1 \
"TotalE_all/rdf_".word(list_sel1, i)."-".word(list_sel2, j).".dat" u 1:(2*$2+count) w lines dt "-" lw 2 title "",\
count = 106
plot for [i=1:words(list_sel1)] \
for [j=i:words(list_sel2)] \
count = count-1 \
"Successes_all/rdf_".word(list_sel1, i)."-".word(list_sel2, j).".dat" u 1:(2*$2+count) w lines lw 6 title word(list_sel1, i)."-".word(list_sel2, j),\
unset multiplot
##################
# pointtype ("pt")
# 0 = none
# 1 = horz.line
# 2 = X
# 3 = X & horz.line
# 4 = open box
# 5 = closed box
# 6 = open circle
# 7 = closed circ.
# 8 = open up triang.
# 9 = closed up triang.
# 10= open down triang.
# 11= closed down triang.
# 12= open diamond
# 13= solid diamond
# linetype ("lt")
# -1 = black
# 0 = grey dotted
# 1 = purple
# 2 = green
# 3 = sky blue
# 4 = orange
# 5 = yellow
# 6 = navy blue
# 7 = red
# \305 = Angstrom
# {/Symbol *} = Greek *