# Strange errors with tikz

I'm relatively new to LaTeX and as a result of playing around with it in sharelatex, I've started a few pages on calculus. I want to render this graph:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel={$f(x) = sin(x)$}
]
\end{axis}
\end{tikzpicture}\\

\end{document}


but it renders a wrong one, a graph I used before (f(x) = x/2).

How can I fix this?

– user31729
May 5 '17 at 20:54
• Welcome! Please edit your code to provide a complete minimal example which reproduces the problem when we compile it. Are you sure that you don't just have an error so that the compilation of the new document does not succeed? Off-topic: don't use \\  for line breaks outside special environments such as tabular and array.
– cfr
May 5 '17 at 20:55
• How do I conviniently make line breaks, then? May 5 '17 at 20:57
• to see sinus function you should define domain. for example \addplot[domain=-180:180] {sin(x)}; May 5 '17 at 20:57
• @WzYDWzt: Your code does not show that you use f(x) = x/2 ....
– user31729
May 5 '17 at 20:57

Completing your code to MWE and defining domain for sin(x) I obtain:

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel={$f(x) = \sin(x)$}
]
\end{axis}
\end{tikzpicture}
\end{document}


For more smooth curve you can define number of samples or add option smooth to addplot.

A few things:

Use \sin instead of sin

The sin function uses degrees, not radians

The samples option indicates at how many points the function should be evaluated.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel={$f(x) = \sin(x)$}
]