Posts mit dem Label latexterm werden angezeigt. Alle Posts anzeigen
Posts mit dem Label latexterm werden angezeigt. Alle Posts anzeigen

Montag, 28. April 2014

make gnuplot produce a latex standalone document

gnuplot has a view very good terminals including the epslatex-terminal the only backdraw which i had recently was that the terminal produces either:
- a latex file which can be included in the latex-document
or
- a latex-document which produces a pdf with the minimal-documentclass
but it does not produce a document which can be used via includestandalone.

But now I found a way to do it.

1.  create example with epslatex terminal


set terminal epslatex
set output "test.tex"
plot sin(x)
set output

2. Add preamble for standalone figure and add \end{document}

Add at the beginning of test.tex:
 \documentclass{standalone}
\usepackage{graphicx}
\begin{document}

Add at the end of test.tex
\end{document}

PS: I also wrote a gnuplot script doing all of this:

epslatexterm(name, xsize, ysize, gnuplotcommand) = sprintf('\
name="%s";\
file=name.".tex";\
set terminal epslatex size %s, %s;\
%s;\
set output name.".tex";  \
replot; \
unset output;\
eval bash(''echo \" \\\\begin{document}            \" |cat - ''.file.'' > tmp    '');\
eval bash(''echo \" \\\\usepackage{graphicx}       \" |cat - tmp      > tmp2   '');\
eval bash(''echo \" \\\\documentclass{standalone}  \" |cat - tmp2     > tmp    '');\
eval bash(''echo \" \\\\end{document}              \" |cat tmp -      > tmp2   '');\
eval bash("sed ''s/".name."/".name."-inc/g'' tmp2 > ".file  );\
eval bash(''mv ''.name.''.eps ''.name.''-inc.eps'');\
eval bash(''rm tmp tmp2 -f'');\
set terminal wxt; \
',name,xsize,ysize,gnuplotcommand)

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\}"

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.