# Very weird output

I need to output the absolute value function on the axis. Here is my code:

\documentclass[10pt,letterpaper,no-math]{article}
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt
\usepackage{polynom}
\usepackage{anyfontsize}
\usepackage{helvet}
\usepackage{mathpazo}

\renewcommand{\familydefault}{\sfdefault}
\usepackage{graphicx}

\usepackage{amssymb,amsmath}
\usepackage[slantfont,boldfont]{xeCJK}
\setCJKmainfont{SimSun}
\usepackage{mathtools}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usepackage{polyglossia}
\usepackage{unicode-math}
\usepackage{chemfig}
\usepackage{scalerel}
\usepackage{tkz-euclide}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}

\usepackage{fontspec,kantlipsum}

\setmainfont
[    Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-italic,
BoldItalicFont = *-bolditalic,
]{xits}

\DeclareMathSizes{9.8}{6}{4}{4}
\DeclareMathSizes{10.0}{9}{4}{4}
\DeclareMathSizes{10.95}{6}{4}{4}
\DeclareMathSizes{11}{6}{4}{4}
\DeclareMathSizes{12}{6}{14}{4}

\parindent0em
\pagestyle{empty}
\setlength{\parindent}{0in}

\setmathfont
[
Extension = .otf,
BoldFont = *bold,
Ligatures = TeX,
]{xits-math}
\usepackage{graphicx}
\usepackage{array}
\newcommand\scalemath[2]{\scalebox{#1}{\mbox{\ensuremath{\displaystyle #2}}}}
\begin{document}

\text{  y=\lvert x-2 \rvert+\lvert x-3 \rvert+\lvert x-4 \rvert=} \left \{ \begin{aligned} 3x-9, &x\geqslant 4,\\ x-1, &3\leqslant x < 4,\\ 5-x, &2\leqslant x < 3,\\ -3x+9, & x < 2. \end{aligned} \right.\ \qquad

\begin{figure}[!htb]
\centering
\begin{tikzpicture}[
transform shape% <- added to scale nodes too
]
\begin{axis}[
xmin=-2,xmax=8,ymin=0,ymax=9,
no markers,
axis y line=middle,
axis x line=center,
axis equal,
ytick={-2,0,2,3,4,6,8}, % make steps of length 0.5
xtick={0,2,3,4,6,8}, % make steps of length 5
xlabel = {$x$},
ylabel = {$y$},
]

\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}


The output of this function should be left-right symmetric, but strangely, the image after x is greater than 5 disappears.

I checked the range of values for x and it looks like everything is fine. Can someone tell me where the problem is?

If you plot the function over a symmetric domain of the form 3-X:3+X with some positive number X, you will more easily appreciate its symmetry.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}

\begin{document}
\begin{tikzpicture}[
transform shape% <- added to scale nodes too
]
\begin{axis}[
xmin=-2,xmax=8,ymin=0,ymax=9,
no markers,
axis y line=middle,
axis x line=center,
axis equal,
ytick={-2,0,2,3,4,6,8}, % make steps of length 0.5
xtick={0,2,3,4,6,8}, % make steps of length 5
xlabel = {$x$},
ylabel = {$y$},
domain=0.5:5.5
]

\end{axis}
\end{tikzpicture}
\end{document}


BTW, most of your preamble is not related to the problem.

\documentclass{article}
\usepackage{amsmath,mathtools}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}

\begin{document}
Consider the function
$$y~=~\lvert x-2 \rvert+\lvert x-3 \rvert+\lvert x-4 \rvert~=~ \begin{dcases} 3x-9, &x\ge 4\;,\\ x-1, &3\le x < 4\;,\\ 5-x, &2\le x < 3\;,\\ -3x+9, & x < 2\;. \end{dcases}$$
It is symmetric under $x\mapsto 3-x$, see Figure~\ref{fig:f}. To see that more
easily, define $x':=x-3$ (such that $x=3+x'$). Then the function becomes
$$y~=~\lvert x'+1 \rvert+\lvert x'\rvert+\lvert x'-1 \rvert ~=~\lvert 1+x' \rvert+\lvert x'\rvert+\lvert 1-x' \rvert\;,$$
which is obviously symmetric under $x'\mapsto -x'$. To appreciate this symmetry,
we might want to take the domain symmetric in $x'$, which corresponds to an
interval $I=[3-\Delta,3+\Delta]$ with some $\Delta>0$.

\begin{figure}[!htb]
\centering
\begin{tikzpicture}[
transform shape% <- added to scale nodes too
]
\begin{axis}[
xmin=-2,xmax=8,ymin=0,ymax=9,
no markers,
axis y line=middle,
axis x line=center,
axis equal,
ytick={-2,0,2,3,4,6,8}, % make steps of length 0.5
xtick={0,2,3,4,6,8}, % make steps of length 5
xlabel = {$x$},
ylabel = {$y$},
domain=0.5:5.5
]