我正在运行以下代码,我已经用它绘制了几个函数,但是当我用以下函数运行它时,它只绘制轴
\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}