Is it possible to plot with TikZ/pgfplots the function f(x)=sin(\pi \cdot x)?

If so, how?

I want ti to look like the function here: enter image description here

  • 7
    (1) This is clearly a "Do-It-For-Me" question in my opinion -- please show more effort. It is your 13th question. (2) Here's one of many related already existing questions tex.stackexchange.com/questions/12951 or tex.stackexchange.com/questions/16232. (3) I edited the title of the question so that it is maybe more useful for others. Apr 3, 2017 at 14:14
  • I barely know any tikz commands, and I tried doing a bit of coding that didn't work, like `\\addplot [blue, line width = 1, smooth, domain=-3:3] {sin(rad(\pi \cdot x)}; and some other ones. Apr 3, 2017 at 14:18
  • Update: thank you, it helped - I discovered that I needed to use the * character for multiplication, and accidentally discovered that pi is the syntax for the symbol of pi (and not \pi, and I tried so far). Please don't downvote the post. Apr 3, 2017 at 14:19
  • 3
    Then provide a MWE and try 3.14 instead of \pi and * instead of \cdot. Don't mix LaTeX commands for type setting stuff with math commands for plotting stuff. Just have a look at the pgfplots manual. Apr 3, 2017 at 14:20

3 Answers 3


enter image description here

     minor tick num=4,
     grid style={line width=.1pt, draw=gray!10},
     major grid style={line width=.2pt,draw=gray!50},
     axis lines=middle,
    \addplot[domain=-1:3,samples=50,smooth,red] {cos(deg(pi*x))};
  • Thanks a lot, but I already found accidentally how to do it by the time you commented with a bit of help from the link that @Dr. Manuel Kuehner provided above. Apr 3, 2017 at 14:21

One possible:


\usepackage{xcolor} % configurações de cor

\pgfplotsset{my style/.append style={axis x line=middle, axis y line=
        middle, xlabel={$x$}, ylabel={$y$}, axis equal }}


\begin{axis}[my style, grid=both, grid style={padrao-grafico-grid}, width=10cm, xtick={-1,0,...,3}, ytick={-1,0,...,1},
xmin=-2, xmax=4, ymin=-1.2, ymax=1.2]

% gráficos de funções   
\addplot+[mark=none,smooth,color=padrao-grafico2] (\x,{cos(pi*deg(x))});


% remover grid - tirar grid=both, grid style={padrao_grafico4!15}, minor tick num=4
\begin{axis}[my style, grid=both, grid style={padrao-grafico-grid}, width=10cm, xtick={-3,-2,...,3}, ytick={-3,-2,...,3},
xmin=-4, xmax=4, ymin=-4, ymax=4]

%gráfico com legenda
\addplot+[mark=none,smooth,color=padrao-grafico1] (\x,{(e)^\x});

% gráficos de funções   
\addplot+[mark=none,smooth,color=padrao-grafico2] (\x,{\x^2});
\addplot+[mark=none,smooth,color=padrao-grafico3] (\x,{\x});
\addplot+[thick,mark=none,smooth,color=padrao-grafico4] (\x,{2*\x});
\addplot+[ultra thick,mark=none,smooth,color=padrao-grafico5] (\x,{3*\x});

% pontos
\addplot[smooth,mark=x,color=padrao-grafico1] coordinates{(2,3)};
\addplot[smooth,mark=o,color=padrao-grafico2] coordinates{(2,2)};
\addplot[smooth,mark=*,color=padrao-grafico3] coordinates{(2,1)};

% assintota
\addplot[dashed, color=padrao-grafico4] coordinates{(-3,-4) (-3,4)};

% ponto com coordenada
\addplot[smooth,mark=*,color=padrao-grafico3] coordinates{(3,-3)};
\addplot[dashed,very thin,color=padrao-grafico4] coordinates { (3,0) (3,-3) (0,-3) };

\addplot[mark=*] coordinates {(3,0)} node[pin=-50:{$(3,0)$}]{} ;

\addplot[mark=*,color=padrao-grafico4] coordinates {(2,-2)} node[right] {$A$};


  • You should increase the samples (200 is usually ok) to have a more relevant sin function.
    – marsupilam
    Apr 3, 2017 at 14:31

enter image description here

     axis lines=middle,clip=false,
            xticklabel style={black},
                                node[right,pos=0.9,font=\footnotesize]{$f(x)=\sin \pi x$};
                                node[right,pos=1,font=\footnotesize]{$f(x)=\cos \pi x$};

Not the answer you're looking for? Browse other questions tagged .