
tikz로 어떻게 이런 그래프를 그릴 수 있나요?
함수: f(x) = x^2 + 0.25, f(x) = x^2 + 0.1 및 f(x) = x^2 + 0.4
모두 대각선 y=x입니다.
나는 다음과 같이 시작했습니다:
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain = -.6:1,
samples = 50,
axis x line = center,
axis y line = center,
xlabel = {$x$},
ylabel = {$y$},
ticks = none
]
\addplot[blue] {x*x + 0.25};
\addplot[black] {x}
\end{axis}
\end{tikzpicture}
\end{document}
하지만 내가 어디를 놓치고 있는지 모르겠어요
답변1
당신은 매우 가까웠고 몇 줄만 누락되었습니다. 다른 두 플롯을 표시하도록 함수를 변경하는 것은 쉽습니다.
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain = -.6:1,
samples = 50,
axis x line = center,
axis y line = center,
xlabel = {$x$},
ylabel = {$y$},
try min ticks = 10,
scale only axis,
]
\addplot[blue] {x*x + 0.25};
\addplot[black] {x};
\end{axis}
\end{tikzpicture}
\end{document}
답변2
@bmv의 답변 위에 작은 체리를 추가할 수 있다면 다음과 같이 함수를 선언하면 도움이 될 것입니다.
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
% Declare the functions you need
\tikzset{
declare function={
f(\x)=\x*\x + 0.25;
g(\x)= f(\x) - 0.15;
h(\x)= f(\x) + 0.15;
}
}
\begin{axis}[
domain = -.6:1,
samples = 50,
axis x line = center,
axis y line = center,
xlabel = {$x$},
ylabel = {$y$},
try min ticks = 10,
scale only axis,
]
% easy to resuse
\addplot[blue] {f(x)};
% \addplot[red] {g(x)};
% \addplot[green] {h(x)};
\addplot[black] {x};
\end{axis}
\end{tikzpicture}
\end{document}