我正在運行以下程式碼,我已經用它來繪製了幾個函數,但是當我使用以下函數運行它時,它只繪製軸
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{patterns,positioning,calc}
\begin{figure}[H]
\begin{center}
\begin{tikzpicture}
\begin{axis}[
y=1cm,
x=1cm,
axis x line=center,
axis y line=center,
xtick={-1,0,...,12},
ytick={-1,0,...,5},
xlabel={$X$},
ylabel={$Y$},
xlabel style={below right},
ylabel style={above left},
xmin=-1,
xmax=12.5,
ymin=-1,
ymax=5.5]
\addplot+[color=black,smooth] {sqrt(x-6)};
\end{axis}
\end{tikzpicture}
\caption{The graph of $f(x) = \sqrt{x-6}$}
\end{center}
\end{figure}
答案1
歡迎!只要您不嘗試計算負數的平方根,一切都很好。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
y=1cm,
x=1cm,
axis x line=center,
axis y line=center,
xtick={-1,0,...,12},
ytick={-1,0,...,5},
xlabel={$X$},
ylabel={$Y$},
xlabel style={below right},
ylabel style={above left},
xmin=-1,
xmax=12.5,
ymin=-1,
ymax=5.5]
\addplot+[color=black,smooth,domain=6:12.5] {sqrt(x-6)};
\end{axis}
\end{tikzpicture}
\end{document}