在图表上显示差异

在图表上显示差异

我想在一张图上指出使用 f 的线性化估计 f(x) 的误差。为了指示点 A 和 B 之间的距离,我想在它们之间画一条细的垂直线,两端都有箭头。此外,我需要$\delta y$在脚本样式 (或脚注大小) 中排版到这条垂直线的中间,或者,如果空间不足,则排版到垂直线的右侧,垂直居中。我在用户代码中看到以下命令应该很有用。

\draw[|<->|] ((B)!3mm!90:(A)$)
  --node[fill=white,sloped]
  {$\delta y$} ($(A)!3mm!-90:(B)$);

代码:

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=6in,axis equal image,clip=false,
    axis lines=middle,
    xmin=-3,xmax=10,
    domain=-10:10, samples=501,
    xlabel=$x$,ylabel=$y$,
    ymin=-2.5,ymax=,
    restrict y to domain=-2.5:5,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    extra x ticks={2},
    extra x tick labels={$x_{\circ}$},
    yticklabel style={anchor=west},
    yticklabel shift=-4pt,
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=251,latex-latex,domain=-1:5, thin] {(40/(10 * ln(10))) * x - 50/(10 * ln(10)) + 1};
\addplot[samples=501,domain=-0.333:9,blue] {(1/ln(10)) * ln(40*x - 40)}
node[pos=0.8, anchor=north, font=\footnotesize] {$y=\log(40x - 40)$};
\addplot [dashed, latex-latex, samples=251,domain=-5:5] (1,x) node[pos=0.1, anchor=south, font=\footnotesize, sloped] {$x=1$};
\draw [fill] (1.25,1) circle [radius=1.5pt];
\draw [fill] (2,2.30288) circle [radius=1.5pt] node[above left] {$B$};
\draw [fill] (2,1.60206) circle [radius=1.5pt] node[below right] {$A$};
\end{axis}
\end{tikzpicture}
\hspace{\fill}

\end{document}

答案1

使用您提供的命令的稍许变化:

\draw[|<->|,red] ($(2,2.30288)!3mm!90:(2,1.60206)$) -- ($(2,1.60206)!3mm!-90:(2,2.30288)$)
                node[midway, right] {$\delta y$};

得出的结果是:

在此处输入图片描述

笔记:

  • (A)由于您已经对和的坐标进行了硬编码(B),因此我将它们插入到上面的\draw
  • 我还发现将其放置node在绘图之后更容易,但这只是个人喜好。
  • 我消除了fill=white,否则部分图表会被遮挡。
  • 我还消除了最小值和最大值的设置,以x改善y此处提供的图像。

代码:

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
\begin{axis}[width=6in,axis equal image,clip=false,
    axis lines=middle,
    %xmin=-3,xmax=10,
    domain=-10:10, samples=501,
    xlabel=$x$,ylabel=$y$,
    %ymin=-2.5,%ymax=,
    restrict y to domain=-2.5:5,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    extra x ticks={2},
    extra x tick labels={$x_{\circ}$},
    yticklabel style={anchor=west},
    yticklabel shift=-4pt,
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=251,latex-latex,domain=-1:5, thin] {(40/(10 * ln(10))) * x - 50/(10 * ln(10)) + 1};
\addplot[samples=501,domain=-0.333:9,blue, thick] {(1/ln(10)) * ln(40*x - 40)}
node[pos=0.8, anchor=north, font=\footnotesize] {$y=\log(40x - 40)$};
\addplot [dashed, latex-latex, samples=251,domain=-5:5] (1,x) node[pos=0.1, anchor=south, font=\footnotesize, sloped] {$x=1$};
\draw [fill] (1.25,1) circle [radius=1.5pt];
\draw [fill] (2,2.30288) circle [radius=1.5pt] node[above left] {$B$};
\draw [fill] (2,1.60206) circle [radius=1.5pt] node[below right] {$A$};

\draw[|<->|,red] ($(2,2.30288)!3mm!90:(2,1.60206)$) -- ($(2,1.60206)!3mm!-90:(2,2.30288)$)
    node[midway, right] {$\delta y$};
 
\end{axis}
\end{tikzpicture}
\end{document}

相关内容