我需要一些帮助。我是 Tikz 的初学者,我想绘制这条曲线,但我的问题是我没有曲线函数。请帮帮我!
我的 MWE 是:
\documentclass[a4paper,12pt]{article}
\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{graphicx}
\usepackage{float}
\usepackage{pgf,tikz,pgfplots}
\begin{document}
\begin{figure}[H]
\begin{tikzpicture}[>=latex,scale=3]
\draw[->](-0.15,0)--(1.18,0);
\draw[->](0,-0.15)--(0,1.38);
\draw[color=black,samples=100, thick,domain=0:1] plot(\x,{\x});
\end{tikzpicture}
\end{figure}
\end{document}
答案1
欢迎!我会使用pgfplots
withgroupplots
来实现这一点。在我看来,该函数看起来就像一条抛物线。您可以声明函数并以各种变体绘制它们。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[declare function={fleft(\x)=2.5-0.5*(2-\x)*(2-\x);
fright(\x)=\x;}]
\begin{groupplot}[group style={group size=2 by 1,horizontal sep=3em},
width=7cm,height=6cm,
xmin=0,xmax=4,ymin=0,
xtick={0,1,...,4},ytick={0,1,...,4},axis lines=middle,
xlabel={},samples=51]
\nextgroupplot[domain=1:4,ymax=2.8,
legend style={at={(0.05,0.1)},anchor=south west}]
\addplot[smooth,dashed,blue] {fleft(x)+0.2};
\addplot[smooth,dashed,blue] {fleft(x)-0.2};
\addplot[smooth,thick] {fleft(x)};
\addplot[smooth,red,thick,samples=101] {fleft(x)+0.1*sin(x*540)};
\legend{$f+\varepsilon$,$f-\varepsilon$,$f$,$f_N$}
\nextgroupplot[domain=0:4,legend style={at={(0.05,0.95)},anchor=north west}]
\addplot[smooth,dashed,blue] {fright(x)+0.2};
\addplot[smooth,dashed,blue] {fright(x)-0.2};
\addplot[smooth,thick] {fright(x)};
\addplot[smooth,red,thick,samples=101] {fright(x)+0.1*sin(x*540)};
\legend{$f+\varepsilon$,$f-\varepsilon$,$f$,$f_{10}$}
\end{groupplot}
\end{tikzpicture}
\end{document}