添加图案时路径装饰消失

添加图案时路径装饰消失

我想用图案填充曲线下方的区域。曲线有箭头作为装饰。用颜色填充该区域效果很好。 充满

如果我fill用替换pattern箭头装饰就会消失。 图案

梅威瑟:

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis on top = true,
        axis lines = center,
        ticks = none,
        enlargelimits,
        xlabel = $x$,
        ylabel = $y$
    ]
        \addplot[
            pattern = north west lines,
%           fill = yellow,
            postaction = {decorate},
            decoration = {
                markings,
                mark=at position 0.3 with {\arrow{stealth}},
                mark=at position 0.6 with {\arrow{stealth}}
            },
            domain = 0:8,
            samples = 100
        ]
            {16-(x-4)^2}
            \closedcycle;
    \end{axis}
\end{tikzpicture}
\end{document}

如何才能防止箭头被遮住?

答案1

只需使用 apostaction作为模式即可。

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{patterns}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis on top = true,
        axis lines = center,
        ticks = none,
        enlargelimits,
        xlabel = $x$,
        ylabel = $y$
    ]
        \addplot[
            postaction={pattern = north west lines},
            postaction = {decorate},
            decoration = {
                markings,
                mark=at position 0.3 with {\arrow{stealth}},
                mark=at position 0.6 with {\arrow{stealth}}
            },
            domain = 0:8,
            samples = 100
        ]
            {16-(x-4)^2}
            \closedcycle;
    \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

存在依赖于查看器的工件,patterns.meta经常使用可以修复它们。

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{patterns.meta}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis on top = true,
        axis lines = center,
        ticks = none,
        enlargelimits,
        xlabel = $x$,
        ylabel = $y$
    ]
        \addplot[
            postaction={pattern={Lines[angle=45,distance={4pt/sqrt(2)}]}},
            postaction = {decorate},
            decoration = {
                markings,
                mark=at position 0.3 with {\arrow{stealth}},
                mark=at position 0.6 with {\arrow{stealth}}
            },
            domain = 0:8,
            samples = 100
        ]
            {16-(x-4)^2}
            \closedcycle;
    \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

阅读所说的内容这里fill=white,您需要在添加模式之前划定一个区域。只需在模式前输入代码即可。希望它能按您想要的方式工作!

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{patterns}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis on top = true,
        axis lines = center,
        ticks = none,
        enlargelimits,
        xlabel = $x$,
        ylabel = $y$
    ]
        \addplot[
            fill = white,
            pattern = north west lines,
            postaction = {decorate},
            decoration = {
                markings,
                mark=at position 0.3 with {\arrow{stealth}},
                mark=at position 0.6 with {\arrow{stealth}}
            },
            domain = 0:8,
            samples = 100
        ]
            {16-(x-4)^2}
            \closedcycle;
    \end{axis}
\end{tikzpicture}
\end{document}

例子

相关内容