TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

  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}
share|improve this question
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
up vote 9 down vote accepted


    {0}{10}{ sin(4*(x-\ri))/(x-\ri)+cos(2*\ri)*sin(3*\ri)}}


enter image description here

share|improve this answer
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:

\foreach \i in {0.05,0.10,...,10.00}
  \draw plot %

enter image description here

share|improve this answer
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.

\usepackage{lipsum} %for dummy text only.

\backgroundsetup{scale = 1, anchor, angle = 0, position = current page.center,


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);

The result (first page only):

enter image description here

share|improve this answer

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
  • \addplot instead of plot
  • 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.

\pgfplotsset{trig format plots=rad,compat=1.11}
      hide axis,no marks]
      \addplot [very thin] {sin(4*(x-#1))/(x-#1)+cos(2*#1)*sin(3*#1)};}

multiple plots

share|improve this answer

Edited to show no axes.

How does this work for you?


% Declare initial packages

% Normal distribution macro


      hide x axis,
      hide y axis,
      no markers, 
      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,

        \foreach \k in {5,6,...,14} {%
  \addplot [very thick,cyan!50!black] {gauss(\k,3.416969)};

share|improve this answer
What is \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}% doing here? Aesthetics? – Charly Button May 2 '14 at 20:03
If you don't like using a macro, then don't use the macro and embed it. – 1010011010 May 2 '14 at 20:05
You're getting the idea here with your answer, yes, but you have axes, and a some other items in the window. – Charly Button May 2 '14 at 20:07
What is this #1 and #2 business? – Charly Button May 2 '14 at 20:07
#1 and #2 are two variables that you declare as argument of the macro: <function>(<argument1>,<argument2>). While declaring the macro, tell LaTeX that the macro has two arguments, by using \pgfmathdeclarefunction{gauss}{2}{% etc. – 1010011010 May 2 '14 at 20:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.