pgfplots를 사용하여 sqrt{x-1} 그래프를 그릴 때 발생하는 문제

pgfplots를 사용하여 sqrt{x-1} 그래프를 그릴 때 발생하는 문제

저는 현재 pgfplots 패키지를 사용하여 $\sqrt{x-1}$ 함수의 그래프를 그려야 하는 프로젝트를 진행하고 있습니다. 그런데 그래프가 (1,0) 지점을 통과하지 못하는 문제가 발생했습니다.

내 문서 서문에 필요한 \usepackage{pgfplots}를 포함시켰고 그래프가 표시되지만 지점(1,0) 근처에서 예상대로 작동하지 않습니다. 함수 표현식과 패키지 포함을 다시 확인했지만 여전히 이 문제에 직면하고 있습니다.

여기에 이미지 설명을 입력하세요

내 코드의 일부는 다음과 같습니다.

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{booktabs}
\usepackage{tkz-tab}
\usepackage{pgfplots}
\begin{document}
    \begin{center}
                        \begin{tikzpicture}
                            \begin{axis}[
                                xlabel={$x$},
                                ylabel={$y$},
                                axis lines=middle,
                                xmin=-2, xmax=6,
                                ymin=-2, ymax=4,
                                grid=major,
                                domain=-2:6,
                                restrict y to domain=-2:6,
                                samples=100,
                                xtick={-2,-1,0,1,2,3,4,5,6},
                                ytick={-2,-1,0,1,2,3,4,5,6},
                                ]
                                \addplot[blue, thick] {sqrt(x-1)};
                                % Add a node with the text in blue
                                \node[blue] at (axis cs: 5, 2.5) {$(\mathcal{C}_{f})$};
                            \end{axis}
                        \end{tikzpicture}
                    \end{center}
\end{document}

답변1

pgfplots에 대한 다른 대안. 기능은 간단하고 큰 도구가 필요하지 않습니다.

버전 1tkz-fct

\documentclass{standalone}
\usepackage{tkz-fct}
\begin{document}
\begin{tikzpicture}[gridded]
\tkzInit[xmin=-0,xmax=6,ymin=-1,ymax=4]
\tkzAxeX \tkzAxeY
\tkzFct[domain=1:6,samples=800,draw=blue,thick]{sqrt(x-1)}
\end{tikzpicture}
\end{document}

LuaLaTeX가 포함된 버전 2. tkz-fct축에 대해서만 로드했습니다.

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{tkz-fct}
\begin{document}

\directlua{
function f(t0, t1, n)
  local dt = (t1-t0)/n 
  local t = t0
  local out=assert(io.open("tmp.table","w"))
  local x,y
  while (t <= t1) do
    x = t
    y = math.sqrt(t-1)
    out:write(x, " ", y, " i\string\n") 
    t = t + dt
  end
  out:close()
 end
}
\begin{tikzpicture}[gridded]
\tkzInit[xmin=-0,xmax=6,ymin=-1,ymax=4]
\tkzAxeX \tkzAxeY
\directlua{f(1,6,100)}
   \draw[domain=1:6,thick,blue] plot[smooth] file {tmp.table};
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

답변2

\documentclass[12pt]{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{pgfplots}
\begin{document}
    \begin{center}
        \begin{tikzpicture}
            \begin{axis}[
                xlabel={$x$},
                ylabel={$y$},
                axis lines=middle,
                axis equal, % Ensure equal scaling on both axes
                xmin=0, xmax=6,
                ymin=0, ymax=3,
                grid=major,
                domain=1:6,
                restrict y to domain=0:3,
                samples=500,
                xtick={0,1,2,3,4,5,6}, % Include 0 in xticks
                ytick={0,1,2,3},
            ]
            \addplot[blue, thick] {sqrt(x-1)};
            % Add a node with the text in blue
            \node[blue] at (axis cs: 5, 2.5) {$(\mathcal{C}_{f})$};
            \end{axis}
        \end{tikzpicture}
    \end{center}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보