Gnuplot / Ghostscript create a table of content - gnuplot

I'm currently developping a java application that processes information and that info has to be saved as graphs in a pdf file. I got like 60 graphs as output, all with a different title.
What is an easy way to make a table of content from all the graphs based on their title?
Is there a command that can do this? Or do I have to use pdfmarks?
I can't find anything about this on the internet because if I use the words table of content I just get the table of content of gnuplot/ghostscript itself...
Thanks in advance

You can generate the PDF using Latex and then use the epslatex terminal in gnuplot to generate the figures. You can write a script which generates the Latex document.
The gnuplot script:
set term epslatex color size 3,2 font 6
set output "figure1.eps"
#
set title 'Title of figure1'
#
plot sin(x)
#
exit
This generates an EPS file named figure1.eps and a Latex file named figure1.tex which embeds the EPS.
The the following Latex can in turn embed figure1.tex into a document:
\documentclass{article}
\usepackage{graphicx}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[mathcal]{euscript}
\begin{document}
\listoffigures
\begin{figure}
\centering
\include{figure1}
\caption[Description of figure1 as it appears on the list of
figures]{Caption of figure1.}
\end{figure}
\end{document}
Using the \listoffigures command a list of figures will be generated. You might need to run Latex a couple of times before the table appears. Then use dvipdf to export to PDF. The result should look like this:

Related

Introduce a box with special symbols in Gnuplot

I want to have a gnuplot with a box on the right top corner like the one below. My difficulties are both:
how to get \hat{Q} in a the legend?
how to add a box containing the titles?
set term cairolatex eps standalone size 3in,3in
set output 'Q.tex'
set key box opaque samplen 0.5
plot for [i=1:4] sinc(x)**i title sprintf('\tiny${\hat{Q}=%d}$',i) lw 2
The standalone keyword wraps the output in minimal LaTeX commands so that you can run latex Q directly. Omit this if you want to produce a LaTeX fragment for including in a larger document.
I show how to construct a formatted title that includes a LaTeX font size. Note that the format uses single quotes rather than double quotes.
This example uses cairolatex eps because you specifically asked about an eps file. Normallay I would use cairolatex png or cairolatex pdf and process afterwards with pdflatex rather than plain latex.
If you want to include your figure into LaTeX, you should use the terminal cairolatex, then you can include LaTeX code in your plots:
plot "your.data" title '$\hat{Q}=10$'
Concerning your second question, have a look at the manual concerning set key.

Separate file plots from different data files gnuplot

I have 3000 .dat files which I want to plot using gnuplot.
They are all named as "iteration_1", ...", iteration_93", ..."iteration_1247",... (not in the format "iteration_XXXX", if this information is helpful).
Each of those files is to be plotted in an .eps file - my final intention is to do a video (an evolution of those plots), which I can easily make if I have the .eps files.
Is there any way to quickly command gnuplot to do this? All the questions I have found remotely similar to my situation were all actually regarding putting data from different files into one plot in a single file.
Again, I do not want to put all the plots into a single .eps file. I want 3000 .eps files.
Thanks in advance!
Simply put your plotting routine in a do for loop. By the way, gnuplot can also do animated GIFs. Check help gif.
### create output files in a loop
reset session
set terminal epscairo
do for [i=1:3000] {
FILE = sprintf("iteration_%d",i)
set output FILE.".eps"
plot FILE.".dat" u 1:2 w l # or change your extension and plot command accordingly
}
set output
### end of code

How to add a pdf image to a gnuplot plot?

I have an image in PDF format and I want to add to an existing gnuplot plot.
My current code is like:
set terminal postscript eps enhanced color solid font "Nimbus Roman No9 L" 35
set output '|epstopdf --filter > Patterns.pdf'
set size 1.8,1.8
set style data histogram
set style histogram cluster gap 1
plot 'Patterns.dat' using ($2/2.90):xtic(1) title col fs pattern 3
and the pdf file is stored in image.pdf.
It can be done, at least with the epslatex terminal. First, for my example, I am going to generate a pdf file which is a gnuplot-generated figure:
set term epslatex standalone
set output "plot1.tex"
plot sin(x)
Now, outside gnuplot, I generate the pdf file (named plot1.pdf):
pdflatex plot1.tex
which looks like this:
To embed this into a gnuplot graph, I use again the epslatex terminal and embed plot1.pdf as I would do with any pdf file in a latex document, using the \includegraphics[]{} environment, with a gnuplot label:
set term epslatex standalone
set output "plot2.tex"
set label at graph 0.75,0.25 '\includegraphics[width=2cm]{plot1.pdf}'
plot x
And, again run pdflatex:
pdflatex plot2.tex
that generates plot2.pdf, which looks like this:
By changing the location of the label you can change the location of the embedded pdf; by changing the width you can change, guess what, the width of the embedded pdf.

Append pages to existing Postscript file with gnuplot

I want to save some plots that I obtain from different gnuplot programs, ran at different time to go on to the same postscript. At present, if I set the terminal to postscript and give an output file like this:
set terminal postscript eps size 19.2,10.80 enhanced color \
font 'Helvetica,20' linewidth 2
set output 'temp.eps'
gnuplot overrrides the existing file "temp.eps" and plots the new plot in a new file. How can I make it to append another page to the existing postscript?
You can use latex to do this. The following tex file (which I have named test.tex) will embed your eps files (here temp.eps and temp2.eps) into the same PS file:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\centering
\includegraphics[width=0.9\textwidth]{temp}
\newpage
\centering
\includegraphics[width=0.9\textwidth]{temp2}
\end{document}
For which you need to run
latex test.tex
dvips test.dvi
which generates a PS document called test.ps which contains temp.eps in the first page and temp2.eps in the second page.

Gnuplot: is there a way to add small gif icon on the plot?

I am looking for a way to add small icons on the plot, like OK or KO symbols, flags, arrows and such.
So far I've seen an example where you can add a background image, but nothing that actually allow me to set a point on the plot, like I could do with a label, and apply there an icon.
Is there a way to do so?
Call me obsessive but as usual this can be done with the epslatex terminal, embedding the image using a set label statement as you would do in regular latex. If your image is so-icon.png, then within gnuplot do:
set terminal epslatex standalone header "\\usepackage{graphicx}"
set output "plot.tex"
set label at screen 0.5,0.5 '\includegraphics{so-icon.png}'
plot sin(x)
And now run pdflatex
pdflatex plot.tex
Your output will be named plot.pdf and look like this:
Change the positioning of the label (help set label for more info) to wherever you want. You can also use the formatting options of \includegraphics{}, for example \includegraphics[width=2cm]{} for a 2cm wide version of your image (sorry, I don't do inches!).
Note that if you want to embed PNG, JPEG, GIF, PDF and so on, the pdflatex command is required, you cannot use regular latex for those.

Resources