Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Question

I get a very strange graph with pgfplots, see the picture below.

What is going wrong?

Code and picture

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
axis x line = middle, 
axis y line = middle, 
xmin = -1, 
xmax = 1,  
grid = major, 
clip = false]
\addplot[color=orange, smooth, ultra thick] {sin(deg(x))} node[right] {$\sin$};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

share|improve this question
1  
clip=true solve this. –  ferahfeza Apr 7 at 11:48
    
Thanks! But, what if I want clip=false, for other reasons? (see my updated code, with the label "sin" next to to the curve). –  Colas Apr 7 at 11:56

1 Answer 1

up vote 10 down vote accepted

If you use clip=false you turn off the clever trimming mechanism of pgfplots. By default, the domain is larger than -1:1 hence you get the extra drawing (I think it's -6:6 it's -5:5 by default). So you have to adjust the domain too.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
axis x line = middle, 
axis y line = middle, 
xmin = -1, 
xmax = 1,  
grid = major,
domain=-1:1,
clip = false]
\addplot[orange, smooth, ultra thick] {sin(deg(x))};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
Default is -5:5 FYI; otherwise a great explanation! :-) –  Paul Gessler Apr 7 at 12:04
    
@PaulGessler Oh right. Too much pie thinking :) –  percusse Apr 7 at 12:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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