为什么软剪辑域代码在填充两条曲线之间的区域时无法正常工作?

为什么软剪辑域代码在填充两条曲线之间的区域时无法正常工作?

为什么软剪辑域代码无法填充0到3?

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{ decorations.markings,arrows.meta}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[xmin=-1, xmax=9, ymin=-1, ymax=4.5,
            ticks=none,
            xtick distance=0.5,
            ytick distance=0.5,
            axis equal image=true,
            grid,
            grid style={ultra thin, gray!10},
            grid=both,
            axis lines=middle,
            axis line style={->},
            xlabel={$x$},
            ylabel={$y$},
            xlabel style={at={(ticklabel* cs:1)},anchor=west},
            ylabel style={at={(ticklabel* cs:1)},anchor=south}
            ]
            \addplot[name path = A, red, thick, smooth] plot coordinates
            {   (0, 1)
                (1.5, 2.4)
                (3, 0.7)
                (4.3, 2.8)
                (5.4, 3)
                (6.5, 2)
                (7.5, 1)   };
        \addplot[name path = B, blue, thick, smooth] plot coordinates
        {    (0, 2)
            (1.5, 0.8)
            (3, 2.5)
            (5, 0.8)
            (6, 1.3)
            (6.7, 2)
            (7.5, 3)    };
    \addplot [fill=teal!40, opacity=0.5] fill between [of = A and B, soft clip={domain=0:3}];
    \draw (axis cs:7.5,0)--(axis cs:7.5,4);
    \node at (axis cs:7.5,-0.3) {\tiny 1};
    \node at (axis cs:0.2,-0.3) {\tiny 0};
    \node at (axis cs:5,3.5) {\tiny \color{red}$ y=f(x) $};
    \node at (axis cs:5,0.5) {\tiny \color{blue}$ y=g(x) $};
    \end{axis}
    \end{tikzpicture}
\end{document}

答案1

这不是一个答案,而是一个错误报告的 MWE,如果它不存在的话

这既发生在内部,axis也发生在\addplot内部,但值取决于轴刻度。只有在使用该选项时才会发生。只有当边界与路径起点/终点重合时才会发生。tikzpicture\drawsmoothsoft clip path

-因此可以通过延长剪辑来轻松避免这种情况。

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=-2, xmax=3,
ymin=-1, ymax=3,
]
\pgfplotsinvokeforeach{-1,-0.9,...,1}{
\addplot[
smooth,
postaction={decorate, draw, ultra thick, red},
decoration={soft clip, soft clip path={domain=#1:1}},
] plot coordinates{(#1,0) (2,2)};
}
\end{axis}
\end{tikzpicture}
\end{document}

包含多条线条的图表,其中红色部分较粗

相关内容