Dienstag, 30. Juli 2013

gnuplot setup file

So here I am gonna show you my gnuplot setup file, which I load into every gnuplot script, I will put up a standard gnuplot script at some point.
This script can be loaded into gnuplot via:

load "/folder/of/your/gnuplot/script/script.gnu"

 

First part: Linestyles

 #--- LINESTYLES------------------------------------------------------- 
 set style line 1 lt 1 lc rgb "black"  pt 2 lw 2.0 
 set style line 2 lt 1 lc rgb "red"   pt 4 lw 2.0 
 set style line 3 lt 1 lc rgb "blue"  pt 6 lw 2.0 
 set style line 4 lt 1 lc rgb "#44AA44" pt 8 lw 2.0 
 set style line 5 lt 1 lc rgb "#cc7722" pt 10 lw 2.0 
 set style line 6 lt 1 lc rgb "#BBBBBB" pt 12 lw 2.0 

The first paragraph is just to set up a few linestyles in gnuplot which look good, so I set up 6 good looking linestyles, which can be used by typing:
 plot sin(x) ls 1 

Second part: Commands

bash("")

 #--- bash("command") ------------------------------------------------- 
 # -allows to use bash commands in gnuplot 
 bash(cmd) = sprintf('set print "| /bin/bash"; print "%s"; set print', cmd) 

which gives you an command to use bash easily in gnuplot:
 eval bash("echo test")


latexterm("","","","")

 #--- latexterm("name", "xsize", "ysize","command","latexcommand")--\  
 ----------------------------  
 # -sets terminal to epslatex and creates output file with xsize and\  
  ysize  
 latexterm(name, xsize, ysize, command,latexcommand) = sprintf('\  
 name="%s";\  
 xsize="%s";\  
 ysize="%s";\  
 command="%s";\  
 latexcommand="%s";\  
 set terminal epslatex size xsize, ysize color colortext standalone \  
 header "\\usepackage[T1]{fontenc}\n\\usepackage{mathptmx}\n\\usepackage{helvet} ".latexcommand command ; \  
 set output name.".tex"; \  
 replot; \  
 unset output;\  
 eval bash("latex ".name.".tex"); \  
 eval bash("dvips ".name.".dvi"); \  
 eval bash("ps2pdfbb ".name.".ps"); \  
 eval bash("rm -rf ".name.".aux ".name.".dvi ".name.".log ".name.".ps ".name.".tex ".name."-inc.eps"); \  
 set terminal wxt; \  
 ',name,xsize,ysize,command,latexcommand)   

which gives you an terminal which automatically creates an latex file and converts it into pdf (you need a ps2pdfbb script --> i will upload it later, but it can be also found online; the script corrects the wrong bounding box created by gnuplot).
 eval latexterm("test","6cm","4cm","","")


fitcube("","")

 #--- fitcube("plotinfo", "n")----------------------------------------- 
 # -fits a cubic function to the data plotinfo with the name "n" 
 fitcube(plotinfo,n) = sprintf('\ 
 %s(x)=a%s*x**3+b%s*x**2+c%s*x+d%s;\ 
 fit %s(x) %s via a%s,b%s,c%s,d%s;\ 
 print "fitted function is saved in %s(x): \ 
 %s(x)=",a%s,"x**3 + ",b%s,"x**2 + ",c%s,"*x + ",d%s;\ 
 eval bash("rm -f fit.log");\ 
 x1%s =(-2*b%s-sqrt(4*b%s**2-12*a%s*c%s))/(6*a%s);\ 
 x2%s =(-2*b%s+sqrt(4*b%s**2-12*a%s*c%s))/(6*a%s);\ 
 y1%s =%s(x1%s);\ 
 y2%s =%s(x2%s);\ 
 print "extreme points at (",x1%s ,"/",y1%s ,") and (",x2%s ,"/",y2%s ,") \ 
 and are saved in (x1%s /y1%s ) and (x2%s /y2%s )";\ 
 ',n,n,n,n,n,n,plotinfo,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n 
 ,n,n,n,n,n,n,n) 
Fits a cubic function to the function you say it to. It will save the maxima and minima into x1${functionname} y1${functionname} and x2${functionname} y2${functionname}. It allows a continues use of fitcube and storage of all needed parameters, if different names for the function are chosen.

Example to fit a dataset in file "data" with column 1 and 2 into the function named function:

  eval fitcube('"data" u 1:2',"function")

Third part: Macros

set macros 
 redgreenblue_small = "defined (\ 
           0 0.0 0.0 0.5, \ 
           1 0.0 0.0 1.0, \ 
           2 0.0 0.5 1.0, \ 
           3 0.0 1.0 1.0, \ 
           4 0.5 1.0 0.5, \ 
           5 1.0 1.0 0.0, \ 
           6 1.0 0.5 0.0, \ 
           7 1.0 0.0 0.0, \ 
           8 0.75 0.0 0.0, \ 
           9 0.5 0.0 0.0, \ 
           10 0.25 0.0 0.0, \ 
           11 0.0 0.0 0.0 )" 
 redgreenblue = "defined (\ 
           0 0.0 0.0 0.5, \ 
           1 0.0 0.0 1.0, \ 
           2 0.0 0.5 1.0, \ 
           3 0.0 1.0 1.0, \ 
           4 0.5 1.0 0.5, \ 
           5 1.0 1.0 0.0, \ 
           6 1.0 0.5 0.0, \ 
           7 1.0 0.0 0.0, \ 
           8 0.5 0.0 0.0)" 

Macros for 3d colormaps. If will give a tutorial on that in a later blogentry.

Keine Kommentare:

Kommentar veröffentlichen