我从中复制了代码这之前有一篇关于绘制椭圆曲线的文章,但不幸的是,当曲线有两个“部分”时,我不知道如何去除两者之间的连接。这是 MWE
\documentclass[12pt]{report}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.12,
}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1]
\begin{axis}[
xmin=-5,
xmax=5,
ymin=-5,
ymax=5,
xlabel={$x$},
ylabel={$y$},
scale only axis,
axis lines=middle,
domain=-1.912931:3,
samples=200,
smooth,
clip=false,
axis equal image=true,
]
\addplot [black] {sqrt(x^3-2*x+1)};
\addplot [black] {-sqrt(x^3-2*x+1)};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
得出
我如何删除连接这两条线段的线?
答案1
你可以分别画出这两个部分。第一部分由前两个根组成,第二部分由第三个根组成,具体长度随意。
% used PGFPlots v1.15
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.12,
/pgf/declare function={
f(\x) = sqrt(\x^3 - 2*\x +1);
% roots of f(x)
fA = -0.5 - sqrt(5)/2;
fB = -0.5 + sqrt(5)/2;
fC = 1;
},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=-5,
xmax=5,
ymin=-5,
ymax=5,
xlabel={$x$},
ylabel={$y$},
scale only axis,
axis lines=middle,
samples=51,
smooth,
axis equal image=true,
]
% left part
\addplot [domain=fA:fB] {f(x)};
\addplot [domain=fA:fB] {-f(x)};
% right part
\addplot [domain=fC:3] {f(x)};
\addplot [domain=fC:3] {-f(x)};
\end{axis}
\end{tikzpicture}
\end{document}