2

I'm trying to recreate this image of the EM spectrum:

Electromagnetic Spectrum

I would like to draw a sin/cos wave of changing frequency as in the picture.

So far I've been doing something extremely hacky but this less than ideal because I can't change the form of the wave without manually going through and changing all the numbers. Can anyone suggest a more elegant solution that perhaps uses a single sine/cosine function?

\begin{tikzpicture}
\draw (0,0) -- (12,0);
\draw (0.2,1)node[left,font=\tiny] {$y=1$} -- (11.8,1);
\draw (0.2,-1)node[left,font=\tiny] {$y=-1$} -- (11.8,-1); 
\foreach \x in {0,0.5,...,12}{
\draw (\x,-0.2)node [below,font=\tiny,] {\x} -- (\x,0.2) ;
}
\draw[ultra thick, red] (0,0) sin (1,1);    %% the real business in this line
\draw[ultra thick, red] (1,1) cos (2.0,0);    %% the real business in this line
\draw[ultra thick, red] (2.0,0) sin (3,-1);    %% the real business in this line
\draw[ultra thick, red] (3,-1) cos (3.9,0);    %% the real business in this line
\draw[ultra thick, red] (3.9,0)  sin (4.8,1);    %% the real business in this line
\draw[ultra thick, red] (4.8,1) cos (5.6,0);    %% the real business in this line
\draw[ultra thick, red] (5.6,0) sin (6.4,-1);    %% the real business in this line
\draw[ultra thick, red] (6.4,-1) cos (7.2,0);    

 \draw[ultra thick, red] (7.2,0)  sin (7.9,1);    %% the real business in this line
\draw[ultra thick, red] (7.9,1) cos (8.55,0);    %% the real business in this line
\draw[ultra thick, red] (8.55,0) sin (9.2,-1);    %% the real business in this line
\draw[ultra thick, red] (9.2,-1) cos (9.7,0.0);

     \draw[ultra thick, red] (9.7,0)  sin (10.2,1);    %% the real business in this line
\draw[ultra thick, red] (10.2,1) cos (10.6,0);    %% the real business in this line
\draw[ultra thick, red] (10.6,0) sin (11.0,-1);    %% the real business in this line
\draw[ultra thick, red] (11.0,-1) cos (11.3,0); %% the real business in this line 

         \draw[ultra thick, red] (11.3,0)  sin (11.6,1);    %% the real business in this line
\draw[ultra thick, red] (11.6,1) cos (11.8,0);    %% the real business in this line
\draw[ultra thick, red] (11.8,0) sin (12.0,-1);    %% the real business in this line
\draw[ultra thick, red] (12.0,-1) cos (12.2,0); %% the real business in this line 

             \draw[ultra thick, red] (12.2,0)  sin (12.4,1);    %% the real business in this line
\draw[ultra thick, red] (12.4,1) cos (12.55,0);    %% the real business in this line
\draw[ultra thick, red] (12.55,0) sin (12.7,-1);    %% the real business in this line
\draw[ultra thick, red] (12.7,-1) cos (12.85,0); %% the real business in this line 

                 \draw[ultra thick, red] (12.85,0)  sin (13.0,1);    %% the real business in this line
\draw[ultra thick, red] (13.0,1) cos (13.1,0);    %% the real business in this line
\draw[ultra thick, red] (13.1,0) sin (13.2,-1);    %% the real business in this line
\draw[ultra thick, red] (13.2,-1) cos (13.3,0); %% the real business in this line 

 \draw[ultra thick, red] (13.3,0)  sin (13.4,1);    %% the real business in this line
\draw[ultra thick, red] (13.4,1) cos (13.48,0);    %% the real business in this line
\draw[ultra thick, red] (13.48,0) sin (13.56,-1);    %% the real business in this line
\draw[ultra thick, red] (13.56,-1) cos (13.62,0); %% the real business in this line 

     \draw[ultra thick, red] (13.62,0)  sin (13.69,1);    %% the real business in this line
\draw[ultra thick, red] (13.69,1) cos (13.76,0);    %% the real business in this line
\draw[ultra thick, red] (13.76,0) sin (13.82,-1);    %% the real business in this line
\draw[ultra thick, red] (13.82,-1) cos (13.88,0); %% the real business in this line 
\draw[ultra thick, red] (13.88,0)  sin (13.92,1);    %% the real business in this line
\end{tikzpicture}

Current attempt

7

With blueshift.

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[hide axis,red,width=16cm,height=4cm,thick] 
\addplot[domain=20:300,samples=800,        
colormap={}{ % Define the colormap from https://tex.stackexchange.com/questions/243689/create-a-plot-line-with-a-gradient
            color(2cm)=(red);
            color(16cm)=(blue);
        },
        ultra thick, point meta=x*x,mesh]{sin(pow(x,2)/15)};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • marmot...this is what I'm looking for... – RenatoP Dec 11 '18 at 9:14
  • marmot, how can I obtain inverted frequency? I mean: - before major frequency - the low frequency – RenatoP Dec 13 '18 at 7:57
  • @RenatoP Try \addplot[domain=20:300,samples=800, colormap={}{ color(2cm)=(red); color(16cm)=(blue); }, ultra thick, point meta=x*x,mesh]{sin(150*pow(x,1/2))};. You could also ask a new question. Or you could just flip the picture. \begin{tikzpicture}[xscale=-1] \begin{axis}[hide axis,red,width=16cm,height=4cm,thick] \addplot[domain=20:300,samples=800, colormap={}{ color(2cm)=(red); color(16cm)=(blue); }, ultra thick, point meta=x*x,mesh]{sin(pow(x,2)/15)}; \end{axis} \end{tikzpicture} – marmot Dec 13 '18 at 8:07
  • yes, it works! I have one error (unexpected \end {document} after \begin {axis} the first \begin {axis} is not closed, but the file is well compiled and is ok) My last question is: is it possible to have more hight wave and amplitude as you procede? – RenatoP Dec 13 '18 at 9:09
  • @RenatoP Could you please ask a separate question? There is no charge. ;-) (I mean official question, not just comment.) – marmot Dec 13 '18 at 9:14
5

A sine wave with increasing frequency has the expression sin(deg((\fmin+\x*((\fmax-\fmin))/\xmax)*\x)) if the frequency increase is linear, and sin(deg(exp(ln(\fmin)+\x/\xmax*(ln(\fmax)-ln(\fmin)))*\x)) if the frequency increase is exponential. I have seen that the exponential increase seems to provide better looking results. In the following code, set \xmax to the maximum value of x, \fmin to the minimum frequency, and \fmax to the maximum frequency. The commented line uses linear frequency increase, and the uncommented line uses exponential frequency increase.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
    \newcommand{\xmax}{14}
    \newcommand{\fmin}{(pi/3)}
    \newcommand{\fmax}{(2*pi)}
\begin{tikzpicture}[domain=0:\xmax, samples=500]
\draw (0,0) -- (12,0);
\draw (0.2,1)node[left,font=\tiny] {$y=1$} -- (11.8,1);
\draw (0.2,-1)node[left,font=\tiny] {$y=-1$} -- (11.8,-1); 
\foreach \x in {0,0.5,...,12}{
    \draw (\x,-0.2)node [below,font=\tiny,] {\x} -- (\x,0.2) ;
}

% The following line uses linear frequency increase
%\draw[ultra thick, red] plot (\x, {sin(deg((\fmin+\x*((\fmax-\fmin))/\xmax)*\x))} );
% The following line uses exponential frequency increase
\draw[ultra thick, red] plot (\x, {sin(deg(exp(ln(\fmin)+\x/\xmax*(ln(\fmax)-ln(\fmin)))*\x))} );

\end{tikzpicture}
\end{document}

enter image description here

  • how can I invert the frequency: first greater frequency and after less frequency.Finaly I should have first short wave, after hight wave. I do not know "the function. Renato – RenatoP Dec 12 '18 at 8:51
  • javi_gg1 I'munable to made the invertion (before more frequency after less) – RenatoP Dec 14 '18 at 12:17
3

A PSTricks solution only for comparison purposes.

\documentclass[pstricks]{standalone}
\usepackage{pst-plot,pst-calculate}
\begin{document}
\begin{pspicture}[algebraic](0,-1.5)(\pscalculate{2*pi},1.5)
    \psplot[plotpoints=3000]{0}{2 Pi mul}{sin(x^3/2)}
\end{pspicture}
\end{document}

enter image description here

Flipped version

\documentclass[pstricks]{standalone}
\usepackage{pst-plot,pst-calculate}
\begin{document}
\begin{pspicture}[algebraic](0,-1.5)(\pscalculate{2*pi},1.5)
    \psplot[plotpoints=3000]{0}{2 Pi mul}{sin((x-TwoPi)^3/2)}
\end{pspicture}
\end{document}

enter image description here

  • how can I invert the frequency: first greater frequency and after less frequency.Finaly I should have first short wave, after hight wave. I do not know "the function. – RenatoP Dec 14 '18 at 7:50
  • cannot compile, thi is th error: ------------------------------------------------------------------------------------------------------- Package xkeyval Error: potpoints' undefined in families ,pstricks,pst-tools,pst-node,pst-arrow,pst-3d,pstricks-add,pst-plot'. See the xkeyval package documentation for explanation. Type H <return> for immediate help I' ve upload pst-calculate and pst-plot Use pdflatex to compile – RenatoP Dec 14 '18 at 9:07
  • @RenatoP: Compile it with xelatex or latex-dvips-ps2pdf. – Artificial Odorless Armpit Dec 14 '18 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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