我正在尝试绘制一条椭圆曲线,但它留下了一个奇怪的“间隙”。我尝试了不同的域值,但间隙仍然存在。
\begin{tikzpicture}
\begin{axis}[
xmin=-2.5,
xmax=3,
ymin=-5,
ymax=5,
xlabel={$x$},
ylabel={$y$},
scale only axis,
axis lines=middle,
domain=-1.71:3,
samples=200,
smooth,
% to avoid that the "plot node" is clipped (partially)
clip=false,
% use same unit vectors on the axis
axis equal image=true,
]
\addplot [red] {sqrt(x^3+5)};
\addplot [red] {-sqrt(x^3+5)};
\end{axis}
\end{tikzpicture}
答案1
你得到
NOTE: coordinate (2Y1.71e0],3Y0.0e0]) has been dropped because it is unbounded
(in y). (see also unbounded coords=jump).
NOTE: coordinate (2Y1.71e0],3Y0.0e0]) has been dropped because it is unbounded
(in y). (see also unbounded coords=jump).
计算 5 的立方根,例如 Ti钾Z 会的。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\cuberootoffive}{exp(ln(5)/3)}
\begin{axis}[
xmin=-2.5,
xmax=3,
ymin=-5,
ymax=5,
xlabel={$x$},
ylabel={$y$},
scale only axis,
axis lines=middle,
domain=-\cuberootoffive:3,
samples=200,
smooth,
% to avoid that the "plot node" is clipped (partially)
clip=false,
% use same unit vectors on the axis
axis equal image=true,
]
\addplot [red] {sqrt(x^3+5)};
\addplot [red] {-sqrt(x^3+5)};
\end{axis}
\end{tikzpicture}
\end{document}
但仍然存在微小的差距:
没有间隙xfp
并且该图确实是正确的。
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfmath-xfp,xfp}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\edef\cuberootoffive{\fpeval{exp(ln(5)/3)}}
\pgfmxfpdeclarefunction{cubic}{1}{sqrt((#1)^3+5)}
\begin{axis}[
xmin=-2.5,
xmax=3,
ymin=-5,
ymax=5,
xlabel={$x$},
ylabel={$y$},
scale only axis,
axis lines=middle,
domain=-\cuberootoffive:3,
samples=200,
smooth,
% to avoid that the "plot node" is clipped (partially)
clip=false,
% use same unit vectors on the axis
axis equal image=true,
]
\addplot [red] {cubic(x)};
\addplot [red] {-cubic(x)};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
你可以用 pstricks 包绘制隐函数曲线pst-func
。代码如下:
\documentclass[svgnames, pstricks, border=10pt]{standalone}
\usepackage{pst-plot,pst-func }
\begin{document}
\begin{pspicture*}(-3,-5)(3,5)
\psset{plotpoints=4000, showorigin=false, arrowinset=0.12, linejoin=1}
\psaxes[labelFontSize=\scriptstyle,ticksize=0 4pt, Dx=2, Dy=2]{->}(0,0)(-3,-5)(3,5)[$x$,-120][$y$,210]
\psplotImp[algebraic, linecolor=Tomato, linewidth=1.2pt](-4,-6)(4,6){x^3-y^2 + 5}
\end{pspicture*}
\end{document}
答案3
// Run on http://asymptote.ualberta.ca/
unitsize(1cm);
import contour;
import graph;
real f(real x, real y) { return y^2-x^3; }
pair A=(-2.5,-5), B=(3,5);
limits(A,B);
guide[][] g = contour(f,A,B, new real[] {5});
draw(g[0],blue+1pt);
real[] x={-2,2};
real[] y={-4,-2,2,4};
xaxis(Label("$x$",EndPoint,align=N),Ticks(x,1mm,red));
yaxis(Label("$y$",EndPoint,align=E),Ticks(y,1mm,red));
shipout(bbox(5mm,invisible));
答案4
因为 pgfplots 不能(据我所知?)绘制隐式曲线,你必须手动对其进行参数化(或切换到另一个包,如另一个答案中所述),如果您想要好的曲线,您必须找到好的参数化。
这种情况下,让参数为变量 y 效果会更好:
%! TEX program = lualatex
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=-2.5,
xmax=3,
ymin=-5,
ymax=5,
xlabel={$x$},
ylabel={$y$},
scale only axis,
axis lines=middle,
smooth,
% to avoid that the "plot node" is clipped (partially)
clip=false,
% use same unit vectors on the axis
axis equal image=true
]
\addplot [variable=t, domain=-5:5, samples=50, red] ({abs(t^2-5)^0.333333333333*sign(t^2-5)}, {t});
\end{axis}
\end{tikzpicture}
\end{document}
参考:https://tex.stackexchange.com/a/582731/250119(手动参数化示例)如何使用 pgfplots 绘制隐式方程?(如何计算立方根)使用 pgfplots 创建二维参数化参数图(如何绘制参数化图表)