3

I want to plot a graph that looks like this:

The graph needs to look like two bell curves. There's no specific functions or anything for it.

Here's what I have.

\begin{tikzpicture}
    \draw[very thin,color=lightgray,step=0.5cm] (0,0) grid (6.1,3.6);
    \draw[->] (0,0) -- (6.2,0) node[anchor=north] {$t$};
    \draw[->] (0,0) -- (0,3.7) node[anchor=east] {$v$};
    \draw
        (0,0) node[anchor=north] {0}
        (1,0) node[anchor=north] {10}
        (2,0) node[anchor=north] {20}
        (3,0) node[anchor=north] {30}
        (4,0) node[anchor=north] {40}
        (5,0) node[anchor=north] {50}
        (0,1) node[anchor=east] {5}
        (0,2) node[anchor=east] {10}
        (0,3) node[anchor=east] {15};
    \draw[thick,color=blue] (0,0) to [out=0,in=180] (1,3);
    \draw[thick,color=blue] (1,3) to [out=0,in=180] (2,0);
    \draw[thick,color=blue] (2,0) to (4,0);
    \draw[thick,color=blue] (4,0) to [out=0,in=180] (5,3);
    \draw[thick,color=blue] (5,3) to [out=0,in=180] (6,0);
\end{tikzpicture}

As you can see it doesn't really look like bell curves.

I'm very new to TikZ and this is the only way I know how to plot. Please help!

  • Do you have more details, such as the value of v when t is 2,4,6,8 or 12,14,16,18... It will be easier to draw with those value – user156344 Nov 3 '18 at 13:38
  • It's an arbitrarily drawn graph, no points whatsoever. – Steven Sun Nov 3 '18 at 14:12
5

Welcome to TeX.SE! You can plot arbitrary functions. Note that you'd probably make your life more comfortable by drawing this with pgfplots.

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[declare function={Gaussian(\x,\y,\z)=exp(-\z*(\x-\y)*(\x-\y));}]
    \draw[very thin,color=lightgray,step=0.5cm] (0,0) grid (6.1,3.6);
    \draw[->] (0,0) -- (6.2,0) node[anchor=north] {$t$};
    \draw[->] (0,0) -- (0,3.7) node[anchor=east] {$v$};
    \draw
        (0,0) node[anchor=north] {0}
        (1,0) node[anchor=north] {10}
        (2,0) node[anchor=north] {20}
        (3,0) node[anchor=north] {30}
        (4,0) node[anchor=north] {40}
        (5,0) node[anchor=north] {50}
        (0,1) node[anchor=east] {5}
        (0,2) node[anchor=east] {10}
        (0,3) node[anchor=east] {15};
    \draw[thick,color=blue] plot[domain=0:2,variable=\x,samples=101]
    ({\x},{3*Gaussian(\x,1,5)});    
    \draw[thick,color=blue] plot[domain=4:6,variable=\x,samples=101]
    ({\x},{3*Gaussian(\x,5,5)});    
\end{tikzpicture}
\end{document}

enter image description here

Just for fun: a quick pgfplots variant.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[declare function={Gaussian(\x,\y,\z)=exp(-\z*(\x-\y)*(\x-\y));}]
\begin{axis}[axis lines=left,grid=major,xmin=0,xmax=72,ymin=0,ymax=22,
xlabel=$t$,ylabel=$v$]
 \addplot[domain=0:20,thick,blue,samples=101] {15*Gaussian(\x,10,0.1)};
 \addplot[domain=40:60,thick,blue,samples=101] {15*Gaussian(\x,50,0.1)};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

You can of course adjust its appearance.

  • Ahh. Thanks. I love the pgfplots variant. May I know when I should use tikz and when I should use pgfplots? Is there any resources where I can look up examples for both tikz and pgfplots? – Steven Sun Nov 3 '18 at 14:11
  • @StevenSun There is no rule when to use what. However, I'd like to argue that, if one starts to add multiple ticks by hand, it is time to gauge whether one is better off with pgfplots. Both the pgfmanual and the pgfplots manual are very nicely written. Additional examples can be found on this site and on TeXample as well as pgfplots. – user121799 Nov 3 '18 at 14:23
  • What do you mean by "add multiple ticks by hand"? – Steven Sun Nov 3 '18 at 14:54
  • @StevenSun In your example, you have \draw (0,0) node[anchor=north] {0} ...., the analogous lines are not there in the pgfplots variant. – user121799 Nov 3 '18 at 15:01

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.