# TikZ or pgfplots | Plotting a trigonometric function (cos / sin / tan) [closed]

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:

• (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. – Dr. Manuel Kuehner Apr 3 '17 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. – Gal Grünfeld Apr 3 '17 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. – Gal Grünfeld Apr 3 '17 at 14:19
• 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. – Dr. Manuel Kuehner Apr 3 '17 at 14:20

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}%
[grid=both,
minor tick num=4,
grid style={line width=.1pt, draw=gray!10},
major grid style={line width=.2pt,draw=gray!50},
axis lines=middle,
enlargelimits={abs=0.2}
]
\end{axis}
\end{tikzpicture}
\end{document}

• 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. – Gal Grünfeld Apr 3 '17 at 14:21

One possible:

\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}

% CORES DE GRÁFICOS
\usepackage{xcolor} % configurações de cor

% GRÁFICOS
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{my style/.append style={axis x line=middle, axis y line=
middle, xlabel={$x$}, ylabel={$y$}, axis equal }}

\begin{document}

\begin{tikzpicture}
\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

\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
% 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
\label{plot_one}
\addlegendimage{/pgfplots/refstyle=plot_one}\addlegendentry{$y=e^x$}

% gráficos de funções

% pontos

% assintota

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

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

\end{axis}
\end{tikzpicture}

\end{document}

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

\documentclass[border=4mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,clip=false,
xmin=-3,xmax=4,ymin=-2,ymax=2,
ytick={-1,1},
xtick={-2,-1,0,1,2},
xticklabels={$-2$,$-1$,$0$,$1$,$2$},
xticklabel style={black},
xlabel=$x$,
ylabel=$y$]
node[right,pos=0.9,font=\footnotesize]{$f(x)=\sin \pi x$};
node[right,pos=1,font=\footnotesize]{$f(x)=\cos \pi x$};
\end{axis}
\end{tikzpicture}
\end{document}
`