
Ich arbeite derzeit an einem Projekt, bei dem ich den Graphen der Funktion $\sqrt{x-1}$ mit dem Paket pgfplots zeichnen muss. Allerdings bin ich auf ein Problem gestoßen – der Graph scheint nicht durch den Punkt (1,0) zu verlaufen.
Ich habe das notwendige \usepackage{pgfplots} in die Präambel meines Dokuments aufgenommen und das Diagramm wird angezeigt, aber es verhält sich in der Nähe des Punkts (1,0) nicht wie erwartet. Ich habe meinen Funktionsausdruck und die Paketeinbindung noch einmal überprüft, aber dieses Problem besteht immer noch.
Hier ist ein Ausschnitt meines Codes:
\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}
Antwort1
Weitere Alternativen zu pgfplots. Die Funktion ist einfach und erfordert keine großen Tools.
Version 1 mittkz-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}
Version 2 mit LuaLaTeX. Ich habe tkz-fct
nur für die Achsen geladen
% !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}
Antwort2
\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}