像這樣的圖表怎麼畫呢?

像這樣的圖表怎麼畫呢?

我怎麼才能用 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}

相關內容