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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What I want to plot is 3 functions: x=0, y=0, and x=cos^{-1}(x).

The plot and graph of the first two look like this:

\begin{center}
  \begin{tikzpicture}
  \begin{axis}[domain = -1:1, samples = 500, grid = both]
    \addplot[color = red](0, x);
    \addlegendentry{$x=0$}
    \addplot[color = green]{0};
    \addlegendentry{$y=0$}
  \end{axis}

  \end{tikzpicture}
\end{center}

plot of first two functions

Then I add the third:

\begin{center}
  \begin{tikzpicture}
  \begin{axis}[domain = -1:1, samples = 500, grid = both]
    \addplot[color = red](0, x);
    \addlegendentry{$x=0$}
    \addplot[color = green]{0};
    \addlegendentry{$y=0$}
    \addplot[color = blue] {acos(x)};
    \addlegendentry{$\cos^{-1}(x)$}
  \end{axis}

  \end{tikzpicture}
\end{center}

plot with the third function

Everything gets messed up. Why is this?

share|improve this question
up vote 2 down vote accepted

The horizontal domain gives the impression that nothing has changed but because you have suddenly increased the vertical axis to 150 domain=-1:1 becomes invisible.

Also you are using 500 samples to constant plots. Supply individually instead, here is with 130

  \begin{tikzpicture}
  \begin{axis}[grid = both,samples=2]
    \addplot[draw= red,ultra thick,domain=-1:1]{0};
    \addlegendentry{$x=0$}
    \addplot[draw = green,ultra thick,domain=-1:130] (0,x);
    \addlegendentry{$y=0$}
    \addplot[draw = blue,samples = 101,domain = -1:1] {acos(x)};
    \addlegendentry{$\cos^{-1}(x)$}
  \end{axis}

  \end{tikzpicture}

enter image description here

share|improve this answer
1  
That makes a lot of sense! It didn't occur to me that this was the issue because in my mind domain was the opposite direction. And thank you for the suggestion about the samples! – Abe Fehr Mar 6 at 13:17
    
@AbeFehr My pleasure – percusse Mar 6 at 13:54

As it turns out, pgfplots (and the underlying PGF, I think) treat the input to trigonometric functions as degrees, not radians. You can force it to be in radians by the key trig format=rad. This also fixes your y-domain issues:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[domain = -1:1, samples = 500, grid = both]
    \addplot[color = red](0, x);
    \addlegendentry{$x=0$}
    \addplot[color = green]{0};
    \addlegendentry{$y=0$}
    \addplot[color = blue, trig format=rad] {acos(x)};
    \addlegendentry{$\cos^{-1}(x)$}
  \end{axis}

  \end{tikzpicture}
  \end{document}

enter image description here

share|improve this answer
    
Ahh yes, the units were plaguing me as well, thank you for telling me about this! Because @percusse's answer enlightened me about the y-domain, I'm going to accept his. Thank you none the less! – Abe Fehr Mar 6 at 14:41

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.