我正在尝试绘制两个函数(y)的简单图,并阴影化它们之间的区域。当我使用阴影图时,图片中会出现伪影。我尝试过更改边界并将阴影图分成两个(有时是三个或四个),但它们都产生了某种与图片混淆的伪影。我可以改变什么或使用什么技巧来消除这种伪影?
\begin{tikzpicture}
\begin{axis}[
minor tick num=1,
axis y line=center,
axis x line=middle,
xlabel=$x$,ylabel=$y$
]
\addplot[name path=f(y),smooth,black,mark=none,
domain=-0.23:1.1,samples=40] (12*x*x-12*x*x*x,x);
\addplot[name path=g(y),smooth,black,mark=none,
domain=-0.23:1.2,samples=40] (2*x*x-2*x,x);
\addplot [blue!50!,opacity=0.4] fill between[of=f(y) and g(y),soft clip={domain y=-0.166:1}];
\node at (1.1,0.15) {\footnotesize $f(y)=12y^2-12y^3$};
\node at (-0.85,0.9) {\footnotesize $g(y)=2y^2-2y$};
\end{axis}
\end{tikzpicture}
答案1
太期待评论了...
我无法重现您的“工件”。在测试中,我对您的代码片段进行了一些清理和缩短。我将其扩展为 MWE(最小工作示例),如下所示:
\documentclass[margin=2mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{intersections}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
minor tick num=1,
axis y line=center,
axis x line=middle,
xlabel=$x$,ylabel=$y$,
% new
enlarge x limits,
domain=-0.23:1.1, samples=40,
smooth,
]
\addplot[name path=f(y)] (12*x*x-12*x*x*x,x);
\addplot[name path=g(y)] (2*x*x-2*x,x);
\addplot [blue!50!,opacity=0.4]
fill between[of=f(y) and g(y),soft clip={domain y=-0.166:1}];
\node at (1.1,0.15) {\footnotesize $f(y)=12y^2-12y^3$};
\node at (-0.85,0.9) {\footnotesize $g(y)=2y^2-2y$};
\end{axis}
\end{tikzpicture}
\end{document}