在 tikz/pgfplots 中描绘和打开区域

在 tikz/pgfplots 中描绘和打开区域

以下代码描绘了平面上的一个封闭的 2D 区域。
我想让该区域看起来在轮廓的底部附近有一个开口,但我不确定如何做到这一点。有人有什么建议吗?

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{pgfplots}
\usetikzlibrary{decorations.markings,arrows, calc, patterns}
\usepgfplotslibrary{patchplots}
\begin{document}

\definecolor{tufte1}{rgb}{0.7,0.7,0.55}
\begin{tikzpicture}

\draw [-stealth] (-1,1.75) -- (6,1.75) node [above left]  {$u$};
\draw [-stealth] (0,-.25) -- (0,6) node [below right] {};

\node [below right,darkgray] at (+1,+1) {$L(u)$};
\node [above right,darkgray] at (+3.75,+3.75) {$U(u)$};

\begin{axis}[
smooth,
stack plots=y,
area style,
enlarge x limits=false,
hide axis]
\addplot[color=white, draw=none]
coordinates
{(0,.85) (.75,.5) (1.75,.35) (2.25,.25) (3,0) (5,0)}
\closedcycle;
\addplot[opacity=0.6,fill=tufte1,
    draw=black]
coordinates
{(0,1) (1,.7) (2,1.5) (3,.5) (4,.15) (5,0)}
\closedcycle;
\end{axis}

\begin{axis}[
smooth,
stack plots=y,
enlarge x limits=false,
hide axis]
\addplot[thick]
coordinates{
(0,.85) (.75,.5) (1.75,.35) (2.25,.25) (3,0) (5,0)
};
\addplot[thick] 
coordinates{
(0,1) (1,.7) (2,1.5) (3,.5) (4,.15) (5,0)
};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture} 
\begin{axis}[smooth,colormap/greenyellow,hide axis] 
\addplot[point meta=x,ultra thick]
coordinates{
(0,1) (1,.7) (2,1.5) (3,.5) (4,.15) (5,0)
};
\end{axis} 
\end{tikzpicture}
\end{document}

答案1

这是我采用的另一种方法。通过这种方法,我能够实现开放边界的外观,但代价是牺牲了封闭区域轮廓的准确性。我需要手动调整这些轮廓,以便即使图形放大,它们看起来也一致。然而,一种消除猜测的方法将是理想的。

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{pgfplots}
\usetikzlibrary{decorations.markings,arrows, calc, patterns}
\usepgfplotslibrary{patchplots}
\begin{document}

\definecolor{tufte1}{rgb}{0.7,0.7,0.55}

\begin{tikzpicture}

\draw [-stealth] (-1,2.05) -- (6,2.05) node [above left]  {$u$};
\draw [-stealth] (0,-.25) -- (0,6) node [below right] {};

\node [below right,darkgray] at (+2.25,+1.5) {$\bf L(u)$};
\node [above right,darkgray] at (+3.9,+4.5) {$\bf U(u)$};

\begin{axis}[
smooth,
axis line style = { draw = none },
xtick = {.75, 3.},
ytick = \empty,
xticklabels={$u_{l}$,$u_{h}$,},
enlarge x limits=false,
xmajorgrids=true,
grid style=dashed,
]
\addplot[opacity=0.6,fill=tufte1, draw=white]
coordinates
{(0,.85) (.75,.5) (1.75,.35) (2.15,.25) (3,0)
(3.5,.05) (4,.15) (3,.5) (2,1.45) (1,.95) (0,1.5)};
\addplot[ultra thick, draw=black]
coordinates
{(0,.85) (.75,.5) (1.75,.35) (2.15,.25) (3.0,.0025)};
\addplot[ultra thick, draw=black]
coordinates
{(4.0,.155) (3,.5) (2,1.45) (1,.95) (0,1.5)};
\end{axis}

\end{tikzpicture}
\end{document}

相关内容