0

I am trying to plot an acos graph using tikz and pgfplots where the function should receive x-2 as an argument to plot the graph of acos(2-x) which gives the acos(x) function a h-shift to the right and a reflection on the y-axis

\begin{tikzpicture}
\begin{axis}[
    smooth,
    no markers,
    axis lines=center,
    xlabel=$x$,
    ylabel=$y$,
    xmin=-1.0, xmax=1,
    ymin=-0.2 , ymax=180,
]

\addplot[name path=A, domain=-1:1, samples=101]{acos(2-x)};

However, I always get the following error when compiling:

Missing number treated as zero
Illegal unit of measure (pt inserted)

Adding r at the end of the 2-x does not help either.

3
  • I am compiling with Overleaf, by the way. Commented Jan 30, 2020 at 20:00
  • 3
    You are asking pgf to compute acos of 3... please adjust the domain such that the argument of acos is between -1 and 1.
    – user194703
    Commented Jan 30, 2020 at 20:03
  • Actually, I understood what you meant eventually...kinda. So after changing the domain from -1:1 to 3:[any number >3] it plots with no issues. Commented Jan 30, 2020 at 20:37

1 Answer 1

0

The problem with your code is that it asks pgf to compute acos of 3 and other values that are outside of its domain. Another problem is that you present only fragments. Here is a simple way to shift the graph to the right and reflect it at the vertical axis: instead of \addplot <function(x)>; use \addplot (<hshift-x,{function(x)});.

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    smooth,
    no markers,
    axis lines=center,
    xlabel=$x$,
    ylabel=$y$,
    ymin=-0.2 , ymax=180,
]
\addplot[dashed, domain=-1:1, samples=101] {acos(x)};
\addplot[name path=A, domain=-1:1, samples=101] (2-x,{acos(x)});
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

The dashed curve is just the untransformed acos function to show that this work.

You must log in to answer this question.

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