# How to get multiple plots of particular functions?

I'm trying to understand how I can get multiple plots from a set of functions to be plotted in the same window without the clutter; i.e., border, axes, grid, whatever... For example, say I want the set of 100 functions S = {f : f(x)=sin(4*(x-i))/(x-i)+cos(2*i)sin(3*i) 0<i<=5 i∈{0.05, 0.10, ... , 5.0}} to be plotted in the same window without the clutter and so that I can rotate, scale, etc. afterwards to ultimately make as a "watermark" background that will fly diagonally across the document. I'm certain this will look quite fabulous with sufficient tinkering with the function, but for example let's go with this S.

I've got some C++ code---it's just a simple for loop---I've made that will help me create the list of functions---you know, metaprogramming, making code that makes code. The metaprogramming aspect of this question will be quite easy once I figure out what the general form of function plotting looks like in LaTeX---I've never plotted anything using LaTeX before.

How can I replace the image with these plots?

\backgroundsetup{%
scale=5.75,       %% change accordingly
angle=25,       %% change accordingly
opacity=.1,    %% change accordingly
color =black,  %% change accordingly
contents={\begin{tikzpicture}[remember picture,overlay]
\node at ([yshift=12.5pt,xshift=5pt]current page.center) {\includegraphics[width=5cm]{wave.jpg}};%\includegraphics[width=5cm]{wave.jpg}
\end{tikzpicture}}
}
-
Am I correct in thinking that all you are after here is 'How to create plots in (La)TeX?'. – Joseph Wright May 2 '14 at 19:55
I want plots without the clutter, that upon rotation don't pixelate, and that can handle 101 functions in one window. How does one make this plot a watermark? There is more to what I'm after here. – Charly Button May 2 '14 at 19:57
I don't see where 'window' comes here: (La)TeX creates either DVI or PDF files, which have pages. Certainly plots done in LaTeX are vector-based so can be scaled/rotated without loss of precision. Watermarking is a separate but quite doable task. – Joseph Wright May 2 '14 at 20:00
My current method is to just generate the list of functions I want for my design, export as bitmap, and then incorporate into my document via \includegraphics; however, upon rotation of the image, pixelation occurs. I want to avoid this at all cost. – Charly Button May 2 '14 at 20:02
i=0 is not possible ;-) (You have a division by zero) – Herbert May 2 '14 at 20:17

\documentclass[pstricks]{standalone}
\usepackage{pst-plot}

\begin{document}

\begin{pspicture}(0,-2)(10,5)
\multido{\ri=0.05+0.10,\iA=0+1}{100}{%
\psplot[algebraic,plotpoints=1000,linecolor=blue!\iA]%
{0}{10}{ sin(4*(x-\ri))/(x-\ri)+cos(2*\ri)*sin(3*\ri)}}
\end{pspicture}

\end{document}

-
How sensational... Minimal too... – Charly Button May 2 '14 at 20:15
I think the mountains in the background are following the contour of cos(2x)sin(3x); that was what I wanted. – Charly Button May 2 '14 at 20:17
The intensity of the blue color is proportional to i – Herbert May 2 '14 at 20:20
I noticed that. I'm playing with it now. Where is there documentation on how to use this? In particular, this portion: \multido{\ri=0.05+0.10,\iA=0+5}{20} – Charly Button May 2 '14 at 20:22
Run texdoc pst-plot and/or texdoc multido. And blue!20 means 20% of blue. – Herbert May 2 '14 at 20:24

Admittedly, pstricks is more efficient for this sort of thing since it can write postscript code for the functions directly, while TikZ/pgf spins its wheels at compile-time computing coordinates for all the points.

But nonetheless, a solution in plain TikZ:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[samples=400,domain=0:10,black!25]
\foreach \i in {0.05,0.10,...,10.00}
\draw plot %
(\x,{sin(4*(\x-\i)*180/pi)/(\x-\i)+cos(2*\i*180/pi)*sin(3*\i*180/pi)});
\end{tikzpicture}
\end{document}

-
What about making it a background watermark? I want to use the existing code that I have. See edit... – Charly Button May 2 '14 at 21:32
@CharlyButton, \includegraphics supports PDF, so you could create any one of these options in a separate file and include it in your main document (vector format maintained) that way. – Paul Gessler May 2 '14 at 21:44
Oh I see. I'll try that now. – Charly Button May 2 '14 at 21:45

Here's an example using Asymptote to create a background image that has exactly the same width as the page. (If the page had different dimensions, the height would be shrunk instead, as the code is currently written.) Since C++ seems to be your language of choice, you may appreciate that the Asymptote syntax is similar, especially compared to something like \multido.

This should be compiled with the shell-escape option enabled.

\documentclass{article}
\usepackage{lipsum} %for dummy text only.
\usepackage{asypictureB}
\usepackage{background}

\backgroundsetup{scale = 1, anchor, angle = 0, position = current page.center,
contents={\includegraphics{background-image.pdf}}}

\title{Title}
\author{Author}
\date{\today}

\begin{document}
\maketitle
%
\begin{asypicture}{name=compile_background}
settings.outformat = "pdf";
size(@the@paperwidth, @the@paperheight);
import graph;
// Deal with what happens when denominator equals 0:
real sinc(real x) {
if (x == 0) return 1;
else return sin(x)/x;
}
for (real i = 0.05; i <= 10; i += 0.05) {
real f(real x) {
return 4*sinc(4*(x-i)) + cos(2i)*sin(3i);
}
path g = graph(f, 0, 10, n=400, operator ..);
draw(g, 0.25*black + 0.75*white);
}
shipout(prefix="background-image");
\end{asypicture}
%
\lipsum[2-11]
\end{document}

The result (first page only):

-

A solution with PGFPlots. I made the parameters similar to Paul's post, the differences are

• I showed \pgfplotsinvokeforeach which is capable of expanding it's argument, not needed here but good to know for the case \foreach would not work
• directly working with radian instead of multiplying a 180/pi factor, a new feature of pgfplots 1.11, so at least version 1.11 is required
• no backslash before the variable x

I compiled with LuaLaTeX which provides more memory for large plots like this.

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[samples=300,domain=0:10,black!30,
hide axis,no marks]
\pgfplotsinvokeforeach{0.05,0.10,...,10.00}{
\end{axis}
\end{tikzpicture}
\end{document}

-

Edited to show no axes.

How does this work for you?

\documentclass{article}

% Declare initial packages
\usepackage{pgfplots}

% Normal distribution macro
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
hide x axis,
hide y axis,
no markers,
domain=2.5:25.5,
samples=100,
xlabel=\empty,
ylabel=\empty,
every axis x label/.style={at=(current axis.right of origin),anchor=west},
every axis y label/.style={at=(current axis.above origin),anchor=south},
height=5cm, width=12cm,
xmin = 4, xmax=24,
xtick={14}, ytick=\empty,
enlargelimits=false,
clip=false,
grid=major
]

\foreach \k in {5,6,...,14} {%