曲线与垂直线交点位置错误

曲线与垂直线交点位置错误

name path = curve在下面的例子中,绿色曲线( )和垂直线( )之间的交点name path = vertical是错误的,而且我还得到了一个包 pgf 错误:No shape named intersection-1 is known. \end{axis}我的例子中有什么错误?

\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage[T2A,T1]{fontenc}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{decorations.text}
\usetikzlibrary{intersections}
\usetikzlibrary{arrows}
\usepgfplotslibrary{fillbetween}

\begin{document}

\begin{tikzpicture}
\begin{axis}[xmin=-0.4, xmax=1, ymin=-10, ymax=60, axis lines = center,
clip=true,
width=13cm,
height=13cm,
xlabel={$r$},
x label style={at={(axis cs:1,0)},
anchor=north,
font=\normalsize},
ylabel={$U_{eff}$},
y label style={at={(axis description cs:0.15,1)},
anchor=south,
rotate=0,
font=\normalsize},
xtick=\empty,
ytick=\empty,
]
\addplot[name path=curve, ultra thick, green, domain=0.05:1,samples=1000]{1/x^2-0.05/x^3};
\draw [name path = vertical] (axis cs:0.2,50) -- (axis cs:0.2,-10) ;
\draw [name intersections={of=curve and vertical, by=Pe}] (Pe) -- (axis cs:0,0);
\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案1

手册中有一个警告,tikz不要试图找到具有“大量非常小的段”的图的交点。所以也许samples=1000太大了。事实证明,对于这个特定的图,使用samples=500对我来说是有效的。如果看起来不够平滑(图的顶部似乎有一个微小的扭结),您可以添加关键字smooth

\addplot[name path=curve, ultra thick, green, %
  domain=0.05:1,samples=500, smooth]{1/x^2-0.05/x^3};

相关内容