Key features:
text within image ("labels"), aligned subscripts and superscripts, function fitting/curve fitting, multiple images in same output ("multiplot"), four plots/2-by-2 figure ("multiplot"), figures with shared axes, touching axes, no margins ("tmargin/bmargin/lmargin/rmargin"), removed axis labels, multi-dimensional data/high-dimensional data/3-dimensional data, log scale, forcing fitted parameters to be positive/greater than zero, square graph ratio, gnuplot code variables/aliases, publication quality
This image is Fig. 4 from my fifth publication.
This figure has several very useful features that can be tricky to learn in gnuplot:
Two-dimensional plots of three-dimensional (or higher) data. Look for set dummy r1, r2, r3 in the script below.
Function/curve fitting. Look for lines like fit disp3C6(r1,r2,r3) in the script below. In this script, you'll find all fit lines commented out. This is because I often set up a script to perform the fitting; execute the script once to do the fitting and obtain the fitted parameters; then enter the fitted parameters in the script and execute a final time without fitting. This is simply a personal habit, but is a method that helps save/backup the fitted parameters as well as makes reading the final script very obvious with respect to the exact (parameterized) function being plotted.
Forcing fitted parameters to be positive (greater than zero). By default, gnuplot fits all parameters on the range of (-infinity, +infinity). Substituting parameters to be fitted with square parameters is a simple way to ensure that the final parameter is positive. See parameters such as Kcao6**2 in the script below. Notice that, while gnuplot will output the value of Kcao6, the value I am interested in is Kcao6**2, which must always be positive.
Saving function fitting/parameterization information to a log file. See set fit logfile in near the top of the script. In addition to what gnuplot prints to STDOUT, this option turns on the printing of special fitting information to a chosen filename/destination.
Writing additional output to the same log file. See set print "filename" append near the top of the script, where filename is whatever file you want to write to. This option allows you to use special print statements within your script, whose output can be saved to the log file instead of STDOUT.
Aligned/shared axes. This can be a bit tricky, and will definitely require a bit of trial and error to get exactly what you want. The figure below uses set size square to fix the overall figure to have a square ratio. Then I defined custom gnuplot variables, e.g. TMARGIN, which are used later in the script by, e.g. @TMARGIN. These variables allow me to selectively add/remove margins from each of the 4 plots in my 2x2 composite graph as appropriate so that each plot shares the desired edges with its neighbor plots.
reset
set terminal pngcairo truecolor nocrop enhanced font "arial,80" size 4800,4800 ## good ratio for publication: 1.336
set size square
#set encoding utf8
set encoding iso_8859_1
set output "SAPT_4solutes_MultiPlot_v3.png" ## output filename
set fit logfile "SAPT_4solutes_MultiPlot_v3.log"
set print "SAPT_4solutes_MultiPlot_v3.log" append
set multiplot layout 2,2 title ""
## SETTINGS FOR WHOLE PLOT
unset grid ## alternatively, use "with lines" after "plot"
set samples 10000 ## default=100... improves smoothness
set border 15 lw 9
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 lmargin 7.0
#set rmargin 2.0
#set tmargin 2.0
#set bmargin 0.5
set logscale x
set logscale y
set pointsize 6
LW = "lw 8"
POS_label = "at graph .1,.9"
TMARGIN = "set tmargin at screen 0.98; set bmargin at screen 0.55" ## @TMARGIN; @LMARGIN | @TMARGIN; @RMARGIN
BMARGIN = "set tmargin at screen 0.55; set bmargin at screen 0.12" ## --------------------|--------------------
LMARGIN = "set lmargin at screen 0.12; set rmargin at screen 0.55" ## @BMARGIN; @LMARGIN | @BMARGIN; @RMARGIN
RMARGIN = "set lmargin at screen 0.55; set rmargin at screen 0.98" ##
## SETTINGS FOR HORIZONTAL AXIS=ABSCISSA
#set xlabel "|SAPT E@^^{(2)}_{disp}(k)| (kcal/mol)" offset 0,0
XLABEL_XTICS = "set xlabel '|SAPT E@^^{(2)}_{disp}(k)| (kcal/mol)' offset 0,0; set format x '%.0g'"
NO_XLABEL_XTICS = "unset xlabel; set format x ''"
set xrange [.00025:.015] ## 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,.003,10 ## this is the spacing between tics on the x-axis
set xtics offset -.25,.25 #out nomirror ## this is the spacing between tics on the x-axis
set mxtics 10 ## frequency of the MINOR x-tics;
## SETTINGS FOR VERTICAL AXIS=ORDINATE
#set ylabel "|Predicted dispersion| (kcal/mol)" offset 0.5,0 # vertical, ordinate label
YLABEL_YTICS = "set ylabel '|model dispersion| (kcal/mol)' offset 0.5,0; set format y '%.0g'" # vertical, ordinate label
NO_YLABEL_YTICS = "unset ylabel; set format y ''"
set yrange [.00025:.015] ## options: "[min:max]" , "[:]" is "perfect" range,
#set format y "" ## "%N.Mf" has N total digits, with M after the decimal.
#set ytics -10,.003,10 ## spacing between tics on the y-axis
set ytic offset .25,0 #nomirror ## spacing between tics on the y-axis
set mytics 10 ## frequency of the MINOR x-tics;
## SETTINGS FOR KEY/LEGEND
set key spacing 1.2 ## vertical spacing between legend lines.
set key samplen .5 ## length of line sample shown in legend.
#set key maxrows 1
#set key maxcolumns 1
set key nobox
set key at graph .95,.2 ## where to put legend: left right center top bottom center
#set key right bottom
#set key font "arial,60"
#set fit limit 1e-6
#set fit maxiter
set fit errorvariables
#set label "CP" at 674.561,80 center
perfect(x) = x
##===== PLOT 1: METHANE =====
## SEE: C:\Users\tryan\Desktop\methane_ff_devel\sapt_0\SAPT_CH4-H2O_dimer_energies_v5.gnu
unset label
set label "methane" @POS_label
@YLABEL_YTICS; @NO_XLABEL_XTICS
@TMARGIN; @LMARGIN
disp_C6_500_short(x) = Ca/(x**6)
Ca = -1246.031
#fit [:12] disp_C6_500_short(x) "500_disp_energies.dat" using 2:(-$5) via Ca
disp_C6_C8_500_short(x) = C6a/(x**6) + C8a/(x**8)
C6a = -732.8179
C8a = -35287.15
#fit [:12] disp_C6_C8_500_short(x) "500_disp_energies.dat" using 2:(-$5) via C6a, C8a
plot \
perfect(x) w lines @LW lc rgb "black" title "",\
"500_disp_energies_sorted.txt" u (-$5):(-disp_C6_C8_500_short($2)) pt 2 @LW lc rgb "red" title "",\
"500_disp_energies_sorted.txt" u (-$5):(-disp_C6_500_short($2)) pt 6 @LW lc rgb "blue" title ""
##===== PLOT 2: ETHANE =====
## SEE: C:\Users\tryan\Desktop\ethane_ff_devel\SAPT_energies\SAPT_C2H6-H2O_dimer_energies_v2c.gnu
unset label
set label "ethane" @POS_label
@NO_YLABEL_YTICS; @NO_XLABEL_XTICS
@TMARGIN; @RMARGIN
dispC6(x,y) = C6co/(x**6) + C6co/(y**6)
C6co = -1051.53
dispC68(x,y) = Cco6/(x**6) + Cco6/(y**6) + Cco8/(x**8) + Cco8/(y**8)
Cco6 = -846.882
Cco8 = -14298.6
plot \
perfect(x) w lines @LW lc rgb "black" title "",\
"SAPT_C2H6-H2O_dimer_energies_EvenDistr.txt" u (-$6):(-dispC68($1,$2)) w points pt 2 @LW lc rgb "red" title "C_{6,i-OW} \\& C_{8,i-OW}",\
"SAPT_C2H6-H2O_dimer_energies_EvenDistr.txt" u (-$6):(-dispC6($1,$2)) w points pt 6 @LW lc rgb "blue" title "C_{6,i-OW}"
##===== PLOT 3: METHANOL =====
## SEE: C:\Users\tryan\Desktop\methanol_ff_devel\SAPT_energies\SAPT_CH3OH-H2O_dimer_energies_v2e.gnu
unset label
set label "methanol" @POS_label
@YLABEL_YTICS; @XLABEL_XTICS
@BMARGIN; @LMARGIN
dispOOCO6(x,y) = -C6co/(x**6) - C6oo/(y**6)
C6co = 1133.02
C6oo = 532.658
#fit dispOOCO6(x,y) "SAPT_CH3OH-H2O_dimer_energies_EvenDistr.txt" using 1:2:6:(1) via C6co,C6oo
dispOOCO68(x,y) = -(Cco6dummy**2)/(x**6) - (Coo6dummy**2)/(y**6) - ((Cco8dummy)**2)/(x**8) - ((Coo8dummy)**2)/(y**8)
Cco6dummy = 34.4683
Coo6dummy = 10.193
Cco8dummy = 23.3538
Coo8dummy = 154.305
#fit dispOOCO68(x,y) "SAPT_CH3OH-H2O_dimer_energies_EvenDistr.txt" using 1:2:6 via Cco6dummy,Coo6dummy,Cco8dummy,Coo8dummy
#Cco6 = 1188.06185799118
#Coo6 = 103.897312942982
#Cco8 = 545.402257205175
#Coo8 = 23810.1397186389
plot \
perfect(x) w lines @LW lc rgb "black" title "",\
"SAPT_CH3OH-H2O_dimer_energies_EvenDistr.txt" u (-$6):(-dispOOCO68($1,$2)) w points pt 2 @LW lc rgb "red" title "",\
"SAPT_CH3OH-H2O_dimer_energies_EvenDistr.txt" u (-$6):(-dispOOCO6($1,$2)) w points pt 6 @LW lc rgb "blue" title ""
##===== PLOT 4: ETHANOL =====
## SEE: C:\Users\tryan\Desktop\ethanol_ff_devel\SAPT_energies\SAPT_ethanol-water_dimer_energies_v1c.gnu
unset label
set label "ethanol" @POS_label
@NO_YLABEL_YTICS; @XLABEL_XTICS
@BMARGIN; @RMARGIN
set dummy r1, r2, r3
disp3C6(r1,r2,r3) = -(K6cao**2)/(r1**6) - (K6cbo**2)/(r2**6) - (K6oho**2)/(r3**6)
K6cao = 32.2875
K6cbo = 27.2611
K6oho = 23.1713
#fit disp3C6(r1,r2,r3) "SAPT_ethanol-water_dimer_energies.txt" using 1:2:3:7 via K6cao,K6cbo,K6oho
#print "#Fitting 3 C6 only: "
#C6cao = -1042.48550671208
#C6cbo = -743.1653379815
#C6cho = -536.908896625053
disp3C63C8(r1,r2,r3) = -(Kcao6**2)/(r1**6) - (Kcbo6**2)/(r2**6) - (Koho6**2)/(r3**6) - (Kcao8**2)/(r1**8) - (Kcbo8**2)/(r2**8) - (Koho8**2)/(r3**8)
Kcao6 = 32.2859
Kcbo6 = 27.2611
Koho6 = 23.1714
Kcao8 = 2.97288
Kcbo8 = 0.357458
Koho8 = 0.0173356
#fit disp3C63C8(r1,r2,r3) "SAPT_ethanol-water_dimer_energies.txt" using 1:2:3:7 via Kcao6,Kcbo6,Koho6,Kcao8,Kcbo8,Koho8
#print "#Fitting 3 C6 & 3 C8: "
#Ccao6 = -1042.3801372749
#Ccbo6 = -743.168944398246
#Coho6 = -536.915276854822
#Ccao8 = -8.83802385367806
#Ccbo8 = -0.127775913309869
#Coho8 = -0.000300521572781371
plot \
perfect(r1) w lines @LW lc rgb "black" title "",\
"SAPT_ethanol-water_dimer_energies.txt" u (-$7):(-disp3C63C8($1,$2,$3)) w points pt 2 @LW lc rgb "red" title "",\
"SAPT_ethanol-water_dimer_energies.txt" u (-$7):(-disp3C6($1,$2,$3)) w points pt 6 @LW lc rgb "blue" title ""
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 *