在 Tikz / Gnuplot 中强制轮廓线连接

在 Tikz / Gnuplot 中强制轮廓线连接

我想要一个障碍函数的漂亮轮廓线。绘制时我得到的是“不相连”的轮廓线。有没有办法强制平滑?

平均能量损失

% !TEX options=--shell-escape
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width = 7cm, compat = newest}
\begin{document}
\begin{tikzpicture}[scale=0.8]
% Representing contour plot on the polytope given by
% x >=0, y>=0, 0.5x+y <=1, y>=x-0.5
% extreme points : (0,0),(0,0.5),(1,0.5),(0,1)

\begin{axis}[
enlarge x limits,
axis lines=none,
ticks=none,
view={0}{90},
small,
]
\addplot[color = violet, mark = none] coordinates{
    (0,0)
    (0,1)
    (1,0.5)
    (0.5,0)
    (0,0)
};
\addplot3[
domain=0:2.3,
domain y=0:1.3,
enlargelimits,
samples = 100,
label = false,
contour gnuplot={levels={3,3.5,4,4.5,5,5.5,6},
labels=false,
handler/.style=smooth},
]{(-ln(x)-ln(y)-ln(1-0.5*x-y)-ln(y-x+0.5))}; 
\end{axis}
\end{tikzpicture}


\end{document}

我得到了在此处输入图片描述 您可以在左侧看到断开的部分。

答案1

这更像是一个耐心问题。如果你增加足够多的样本,轮廓就会很好地连接在一起。

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width = 7cm, compat = newest}
\begin{document}
\begin{tikzpicture}%[scale=0.8] %<- not good, change the width instead
% Representing contour plot on the polytope given by
% x >=0, y>=0, 0.5x+y <=1, y>=x-0.5
% extreme points : (0,0),(0,0.5),(1,0.5),(0,1)

\begin{axis}[
%title={$x \exp(-x^2-y^2)$},
enlarge x limits,
axis lines=none,
ticks=none,
view={0}{90},
small,
]
\addplot[color = violet, mark = none] coordinates{
    (0,0)
    (0,1)
    (1,0.5)
    (0.5,0)
    (0,0)
};
\addplot3[
domain=0.0001:2.3,
domain y=0.0001:1.3,
enlargelimits,
samples = 301,
label = false,
contour gnuplot={levels={3,3.5,4,4.5,5,5.5,6},
labels=false,
handler/.style=smooth},
]{(-ln(x)-ln(y)-ln(1-0.5*x-y)-ln(y-x+0.5))}; 
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

当然,编译时间会激增。

相关内容