我想在 .tex 文档中绘制多个图,但又不想为每条线单独设置线型。因此我使用 '\pgfplotsset{every axis plot/.append style={mark=*, mark size=2pt, line width=1pt, }}' 在整个文档中设置样式。现在,我想添加填充,但命令 \pgfplotsset 与填充结合使用会导致错误。以下是一个简单的示例:
\documentclass[a4paper, 10pt]{scrbook}
\usepackage{adjustbox}
\usepackage{pgf} %Grafikpakete
\usepackage{pgfplots}
\usepackage{tikz}
\usepgfplotslibrary{groupplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{arrows.meta,calc,decorations.markings,math,arrows.meta}
\usetikzlibrary{patterns}
\usetikzlibrary{patterns.meta}
\begin{document}
\pgfplotsset{every axis plot/.append style={mark=*, mark size=2pt, line width=1pt, }}
\begin{figure}[b!]
\begin{adjustbox}{center}
\begin{tikzpicture}
\begin{groupplot}[
group style = {group size = 1 by 1,
horizontal sep=4mm,
vertical sep=4mm,},
height = 0.8*2.5in,
width = 0.6*3.0in,
]
\nextgroupplot[
clip mode=individual,
]
\addplot[name path = A, ] coordinates {(0,1) (1,2)};
\addplot[name path = B, ] coordinates {(1,1) (2,2)};
\addplot[name path = C, ] coordinates {(2,1) (3,2)};
\addplot[name path = D, ] coordinates {(3,1) (4,2)};
\tikzfillbetween[of=A and B, on layer=behindlayer]{ pattern={Lines[angle=45,distance={3pt/sqrt(2)},line width=1pt]}, pattern color=green, opacity=0.25};
\addplot [red, opacity=0.25, ] fill between [of = B and C];
\addplot [pattern={Lines[angle=45,distance={3pt/sqrt(2)},line width=1pt]}, pattern color=blue] fill between [of = C and D];
\end{groupplot}
\end{tikzpicture}
\end{adjustbox}
\caption{}
\end{figure}
\end{document}
有办法让它工作吗?如果没有,我可以定义一个样式变量,然后将其放入添加绘图选项中,如下所示:
line_style = {mark=*, mark size=2pt, line width=1pt, }
...
\addplot[line_style, name path = A, ] coordinates {(0,1) (1,2)};