Key features: 

inverted function/inverse function/function inversion, arrays, generate data points to plot, functions with constants, Greek characters/letters, diamond symbol, text within image ("labels"), text and symbol at specific locations, error bars, publication quality

This image is Fig. 1 from my fourth publication

The most interesting feature of this figure is that it uses a trivial numerical technique to invert a function. The original function I had obtained was density (rho) as a function of temperature (T).* Since I needed to plot T as a function of rho, the pure math solution is to invert the rho(T) function to produce T(rho). However, that inversion would be (analytically) quite tedious. The trivial trick is therefore simply to generate a bunch of paired data points, (T, rho) from the analytic function rho(T), and simply plot them as (rho, T) instead. These data points are simply connected by straight (black) lines. We can produce an arbitrarily smooth curve as desired by using a smaller point spacing (i.e. generating more (T, rho) point pairs). Look for the chunk of code marked ## GENERATE DATA POINTS TO BE "INVERTED": in the script below.

* More precisely, the overall function of density with respect to temperature in the script below is a sum of two functions, diff_6(x) and dens_sum_6(x). Each of those functions contains 6 independent (fitted) constants; these functions are then added and subtracted to produce each of the "arms" on each side of the diamond marked "CP" in the figure below. See the functions dens_liq(x) and dens_gas(x) in the script.

reset 

set terminal pngcairo truecolor nocrop enhanced font "arial,80" size 3078,2303   ## good ratio for publication: 1.336

#set encoding utf8

set output "ManuscriptV6_Figure_1_v3.png"   ## output filename


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 xlabel "{/Symbol r} (mol/L)" offset 0,.5

set xrange [-3:60]   ## options: "[min:max]" , "[:]" is "perfect" range,

#set format x "%1.1f"   ## "%N.Mf" has N total digits, with M after the decimal.

#set xtics 0,50,1000 offset -.25,.25  mirror   ## this is the spacing between tics on the x-axis

set mxtics 2   ## frequency of the MINOR x-tics;


set ylabel "Temperature (K)" offset 1,0   

set yrange [375:700]   

#set format y "%1.1f"   ## "%N.Mf" has N total digits, with M after the decimal.

#set ytic -50,2,0 offset .25,0 #nomirror   ## spacing between tics on the y-axis

set mytics 2   


set key spacing 1.2   ## vertical spacing between legend lines.

set key samplen .5   ## length of line sample shown in legend.

set key maxrows 5   

#set key maxcolumns 1

#set key box lw 6 at screen .925,.925   ## where to put legend: left right center top bottom center

set key nobox   

set key at graph .95,.95   ## where to put legend: left right center top bottom center

#set key font "arial,90"   



#y2 = .1+(3.32560/17)                       #Ending height of "RT" bar= .1 of graph --> RT high.

#labely = y2+.05                            #y-location of "RT" label to be .05 above RT bar.

#set label "RT" at graph .9,labely center   #

#set arrow from graph .9,.1 to graph .9,y2 nohead front lc rgb "black" lw 10       #Main "RT" bar.

#set arrow from graph .875,y2 to graph .925,y2 nohead front lc rgb "black" lw 10   #Upper cap to "RT" bar.

#set arrow from graph .875,.1 to graph .925,.1 nohead front lc rgb "black" lw 10   #Lower cap to "RT" bar.


d   =    .5

B   =    .325

a   =    .11

D   =    .5


diff_6(x) = A0d*((abs(1-x/Tcd))**B) + A1d*((abs(1-x/Tcd))**(B+d)) + A2d*((abs(1-x/Tcd))**(B+2*d)) + A3d*((abs(1-x/Tcd))**(B+3*d)) + A4d*((abs(1-x/Tcd))**(B+4*d)) + A5d*((abs(1-x/Tcd))**(B+5*d))

A0d             =   112.584  

A1d             =  -245.571  

A2d             =   771.586  

A3d             = -1405.97   

A4d             =  1333.4    

A5d             =  -522.671  

Tcd             =   674.561  

Tc_d = Tcd


dens_sum_6(x) = 2*rhoc_d + D1_d*(abs(1-x/Tc_d)**(1-a)) + D1d*(abs(1-x/Tc_d)) + D2d*(abs(1-x/Tc_d)**(1-a+D)) + D3d*(abs(1-x/Tc_d)**(1-a+2*D)) + D4d*(abs(1-x/Tc_d)**(1-a+3*D))

D1_d            = -178.759   

D1d             =  415.198   

D2d             = -401.36    

D3d             =  349.209   

D4d             = -170.798   

rhoc_d          =   17.5698  


dens_liq(x) = (dens_sum_6(x) + diff_6(x))/2

dens_gas(x) = (dens_sum_6(x) - diff_6(x))/2


## GENERATE DATA POINTS TO BE "INVERTED":

array       T[201]

array densliq[201]

array densgas[201]

multfact = (Tcd - 350.)/200

#print multfact

do for [i=1:201] {

temp = (i-1)*multfact + 350

T[i]       = temp

densliq[i] = dens_liq(temp)

densgas[i] = dens_gas(temp)

# print  T[i], densliq[i], densgas[i]

}


set label "CP" at 17.5698,660 center

#set label "CP" at 17.5698,660 center textcolor rgb "blue"



## PLOT "INVERTED" FUNCTION VIA THE GENERATED POINTS CONNECTED BY BLACK LINES.

## ALSO PLOT EXPERIMENTAL DATA POINTS AS LARGE, RED DOTS WITH ERROR BARS.

set pointsize 5

plot   \

densgas using (densgas[$1]):(T[$1]) w lines lc rgb "black" lw 10  title "fitted", \

densliq using (densliq[$1]):(T[$1]) w lines lc rgb "black" lw 10  title "", \

"dens_pres_vs_T.dat" u ($2/18.0152):1:4 w xerrorbars pt 7 lc rgb "red" lw 10  title "simulated", \

"dens_pres_vs_T.dat" u ($5/18.0152):1:7 w xerrorbars pt 7 lc rgb "red" lw 10  title "", \

"< echo '17.5698 674.561' " w points pt 13 lc rgb "black" lw 10  title "", \

# "dens_pres_vs_T.dat" u ($2/18.0152):1 w points pt 7 lc rgb "red" lw 10  title "simulated", \

# "dens_pres_vs_T.dat" u ($5/18.0152):1 w points pt 7 lc rgb "red" lw 10  title "", \


## dens_liq(x) w lines lc rgb "black" lw 6  title "", \

## dens_gas(x) w lines lc rgb "black" lw 6  title "", \


###

# "dens_pres_vs_T.dat" u 1:($2-$5)/18.0152:(($4**2 + $7**2)**.5) w yerrorbars pt 6 lc rgb "red" lw 5  title "", \

# "dens_pres_vs_T.dat" u 1:($2+$5)/18.0152:(($4**2 + $7**2)**.5) w yerrorbars pt 6 lc rgb "red" lw 5  title ""

# diff_6(x) w lines lc rgb "black" lw 6  title "", \

# dens_sum_6(x) w lines lc rgb "black" lw 6  title "", \



##################

# 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 *