
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
非常に近いです。数行が欠けているだけです。関数を変更して他の 2 つのプロットを表示するのは簡単です。
\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}