如何选择选项,例如绘图之间每个填充的全局颜色?

如何选择选项,例如绘图之间每个填充的全局颜色?

我想全局设置文档中每个绘图之间的填充颜色和其他样式选项。我该怎么做?我尝试了以下方法,但没有效果:

\documentclass[tikz]{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

\pgfplotsset{
compat=1.13,
axis lines=center,
every fill between plot/.append style={fill=blue,fill opacity=0.2}
}

\begin{document}

\begin{tikzpicture}
  \begin{axis}
        \addplot[name path = f] gnuplot {x**2};%
        \addplot[name path = x] {0};

        \addplot fill between[of=f and x,soft clip={domain=2:4}];
  \end{axis}
\end{tikzpicture}

\end{document}

即样式选项fill=bluefill opacity=0.2忽略。

答案1

这很可能是一个错误,我也报告过这里

目前 (PGFPlots v1.13)every fill between plot样式似乎只影响图例。与此相反,您可以为样式\addplot fill between中的 s设置样式/tikz/fill between/every segment,但这似乎对图例没有影响。最重要的是,填充颜色似乎仅在图间填充具有(空)可选参数括号时才应用,即\addplot [] fill between...

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
    \usepgfplotslibrary{fillbetween}
    \pgfplotsset{
    % only affects the legend
        every fill between plot/.append style={
            green,
            fill opacity=0.5,
        },
    % only effects the plot
        /tikz/fill between/every segment/.append style={
            red,    % <-- color is only applied when an empty `\addplot' argument is given
            fill opacity=0.2,
        },
        samples=100,
    }
\begin{document}
    \begin{tikzpicture}
        \begin{axis}
            \addplot [name path = f] gnuplot [id=cos] {cos(x)};
            \addplot [name path = x] gnuplot [id=zero] {0};

            %
            \addplot fill between [
                of=f and x,
                soft clip={domain=-2:0}
            ];

            \addplot [
                % without giving these empty brackets,
                % no fill color is applied from the
                % `/tikz/fill between/every segment' style
            ] fill between [
                of=f and x,
                soft clip={domain=0:4}
            ];
            \legend{1,2,3,4}
        \end{axis}
    \end{tikzpicture}
\end{document}

该图显示了上述代码的结果

相关内容