Mittwoch, 31. Juli 2013

gnuplot tikz terminal

 Just now i found out about the tikz terminal in gnuplot 4.6 and just tried it out. It works very nicely, but I think I have to put a little bit of effort into it if its worth to change from pdflatex terminal to lua tikz.
But here is how it works:

Usage

 set terminal lua tikz standalone
 set output "test.tex"  
 plot sin(x)   

standalone/nostandalone/fulldoc

Compiling

 > pdflatex test.tex
immediate compiling only works as far as I saw for standalone and fulldoc

UPDATE COMING SOON

gnuplot if else

gnuplot 4.4 and lower:

 if (<condition>) <command-line> [; else if (<condition>) ...; else ...]
commands are just written after if condition

gnuplot 4.6

 if (<condition>) { <command>; <command>  
  <commands>  
  <commands>  
  } else {  
  <commands>   
  }  
 Commands enclosed in curly brackets.

string comparison:

test eq "test" 

And with this framework you can start building your logical setups in gnuplot, have fun.

gnuplot: key magic

All info about key: www.gnuplot.info

positioning key

 set key top left
top/bottom/centerleft/right

justification of the text

 set key Left
Left or Right (Default)

small tricks

 set key reverse            ## reverse text and sample
 set key samplen <length>   ## change length of samplen
 set key spacing <spacing>  ## set spacing between key lines

Dienstag, 30. Juli 2013

Changing textsize epslatex terminal or latexterm subroutine

 latexterm subroutine

Example file to change the fontsize in my latexterm subroutine:


The way it works:
1. Loading the gnuplot setup file
2. plotting a random function
3. evaluating the latexterm subroutine while renewing the normalsize in latex to another fontsize

 load "gnuplot-setup" 
 plot sin(x) 
 eval latexterm("test","6cm","4cm","",'\n\\renewcommand\{\\normalsize\}\{\\fontsize\{24.88\}\{30\}\\selectfont\}') 

epslatex terminal


In general you can also use it to change the textsize with the epslatex terminal for that you just have to add an option to the epslatex terminal like:

 set terminal epslatex header "\\renewcommand\{\\normalsize\}\{\\fontsize\{24.88\}\{30\}\\selectfont\}"

Imagemagick compose two images

convert pdf into png

convert -density 300 -depth 8 -rotate -90 -quality 85 test.pdf test.png  


compose an inlet into an background:
while resizing the inlet by 15% in both directions
and shifting the inlet by +700 +0
composite -verbose -geometry 15%x15%+700+00 inset.png background.png test.png  

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.

Sonntag, 28. Juli 2013

Hi

Hi,

I am a graduate student in the field of theoretical chemistry and with this blog I mostly just want to remember all the hacks I did for Gnuplot, Latex and all the other scripting languages I use.

Additionally I probably will put up a few setup files for gnuplot, latex, vmd, emacs and so on.

So if you are interested in that keep on looking =)

Best,

Koni