# Tikz/Pgfplots - Can not plot trig functions with a horizontal shift

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,
]



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.

• I am compiling with Overleaf, by the way. Jan 30, 2020 at 20:00
• 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
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. Jan 30, 2020 at 20:37

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,
] The dashed curve is just the untransformed acos function to show that this work.