Saturday, July 10, 2010

Include Symbols and Equations in a gnuplot plot.

To write symbols in a gnuplot plot, first the terminal should be configured and the font file loaded
set terminal postscript eps enhanced "Times-Roman" fontfile "cmex10.pfb"


in the file cmex10.pfb is loaded from the current directory, and the enhanced option enables subindices _  and superindices ^ as in LaTeX.

Each symbol is written by calling the escape sequence  {/Symbol w}. In this example
set xlabel "frequency {/Symbol w}"
w will be rendered as $\omega$.

A complete example: 

# Color plot
set terminal postscript eps color enhanced "Times-Roman" fontfile "cmr10.pfb"
# B&W plot
#set terminal postscript eps enhanced "Times-Roman" fontfile "cmex10.pfb"


set output "plot.eps"


# the image will be resized
set size 0.5,0.4


# set the range of the image
set xrange [-pi:pi]


# remove the souronding borders
set border 3
set xtics nomirror
set ytics nomirror


#show vertical grid 
set grid x


#axis labels
set xlabel "2{/Symbol pw}/N"
set ylabel "penalty" 
set ylabel "decay of |A(i{/Symbol w})|" 
set xtics ( "-{/Symbol p}" -pi, "-{/Symbol p}/2" -pi/2, "0" 0, "{/Symbol p}/2" pi/2, "{/Symbol p}" pi)


#definition of the function
f(x)=abs(x)
f1(x)=abs(x**(1.9))
f2(x)=abs(x**(0.4))


### ls: selects the linestyle
plot f(x) lw 3 title "|{/Symbol 2pw}/N|",\
f1(x) lw 3 title "|{/Symbol 2pw}/N|^{1.9}" 


References:

No comments:

Post a Comment