我正在尝试绘制方程式使用pgfplots
,其图形应该是一个简单的闭合曲线。我使用了以下代码:
\begin{tikzpicture}[>=stealth]
\begin{axis}[
xmin=-1,xmax=3,
ymin=-2,ymax=2,
y=2cm,
x=2cm,
axis x line=middle,
axis y line=middle,
axis line style=<->,
xlabel={$x$},
ylabel={$y$},
]
\addplot[no marks,blue] expression[domain=0:2,samples=2500]{(2*x^3-x^4)^(0.125)};
\addplot[no marks,blue] expression[domain=0:2,samples=2500]{-(2*x^3-x^4)^(0.125)};
\end{axis}
\end{tikzpicture}
但图表看起来像
尚未关闭。有什么建议吗?
答案1
您可以使用samples at
来确保获得以下积分x=2
:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}[>=stealth]
\begin{axis}[
xmin=-1,xmax=3,
ymin=-2,ymax=2,
y=2cm,
x=2cm,
axis x line=middle,
axis y line=middle,
axis line style=<->,
xlabel={$x$},
ylabel={$y$},
]
\addplot[no marks,blue] expression[samples at={0,0.01,...,0.5,0.6,0.7,...,1.91,1.915,1.92,...,1.99,2}]{(2*x^3-x^4)^(0.125)};
\addplot[no marks,blue] expression[samples at={0,0.01,...,0.5,0.6,0.7,...,1.91,1.92,1.93,...,1.99,2}]{-(2*x^3-x^4)^(0.125)};
\end{axis}
\end{tikzpicture}
\end{document}