Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}}
}
share|improve this question
1  
Am I correct in thinking that all you are after here is 'How to create plots in (La)TeX?'. –  Joseph Wright May 2 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 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 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 at 20:02
1  
i=0 is not possible ;-) (You have a division by zero) –  Herbert May 2 at 20:17

4 Answers 4

up vote 2 down vote accepted
\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}

enter image description here

share|improve this answer
    
How sensational... Minimal too... –  Charly Button May 2 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 at 20:17
    
The intensity of the blue color is proportional to i –  Herbert May 2 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 at 20:22
    
Run texdoc pst-plot and/or texdoc multido. And blue!20 means 20% of blue. –  Herbert May 2 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}

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 at 21:32
1  
@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 at 21:44
    
Oh I see. I'll try that now. –  Charly Button May 2 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):

enter image description here

share|improve this answer

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} {%
  \addplot [very thick,cyan!50!black] {gauss(\k,3.416969)};
  }
\end{axis}
\end{tikzpicture}

\end{document}
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 at 20:03
    
If you don't like using a macro, then don't use the macro and embed it. –  1010011010 May 2 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 at 20:07
    
What is this #1 and #2 business? –  Charly Button May 2 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 at 20:10

Your Answer

 
discard

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.