我正在尝试在 groupplot 环境中填充特定图的区域。我已经尝试遵循 pgfplot 手册,该手册对 abd 的说明非常清楚,name path
但\path[] ...
我总是得到同样奇怪的结果(见下图)。由于我使用 x 轴作为填充之间的分界线,因此我开始尝试使用其他东西来检查是否会发生变化。
以下是我的 MWE:
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usepackage{textcomp}
\pgfplotsset{compat=1.18}
\usepackage{siunitx}
\usepackage{tikzscale}
\usetikzlibrary{pgfplots.groupplots}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group name = 4L_keywaveform_sim_S6currentstress,
group size = 1 by 1,
vertical sep = 15pt
},
clip=true,
enlargelimits=false,
height = 0.75\textwidth,
width = \textwidth,
axis x line = bottom,
axis y line = left,
xlabel={$t$},
xlabel style={align=right, anchor=west, xshift=5.8cm, yshift=0.6cm},
x axis line style={shorten >=-15pt},
xmin=0, xmax=12.5,
ymajorgrids=true, yminorgrids = true, xmajorgrids=true, grid style={dashed},
set layers,cell picture=true,
]
\nextgroupplot[ymin=0, %Position colunm 1 by row 1
ymax=15,
ytick align = outside,
ytick pos = left,
axis y line = left,
ylabel = {$y$},
legend columns=1,
]
\addplot[color=blue, name path global = teste1, domain=0:15,
postaction={decorate},% ------
decoration={markings, % ------
mark=between positions 0.05 and 1 step (1/10)*\pgfdecoratedpathlength with {\arrow{Latex}},
},
] {x};
\label{test}; \addlegendentry{$x$};
\addplot[color=red, name path global = teste2, domain=0:15] {-3 + x^2};
\path[name path global = teste3] (axis cs:0,5) -- (axis cs:12.5,5);
\addplot[blue, fill=blue, fill opacity=0.4] fill between[of= teste1 and teste3];
\end{groupplot}
\end{tikzpicture}
\end{document}
为了简化目的,MWE 仅包含 1by1 组图。但 n by m 组图仍然存在问题。
编辑/更新:通过进一步调查,似乎装饰参数与填充之间发生了混淆。不过,我不知道原因是什么。
谢谢,
答案1
装饰postaction
会破坏路径,但它可以与一起使用preaction
。您也可以始终使用该选项添加两次情节forget plot
。
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
xmin=0, xmax=12.5,
ymin=0, ymax=15,
]
\draw[name path=line] (0,5) -- (12.5,5);
\addplot[
name path=plot,
blue,
domain=0:12.5,
preaction={decorate},
decoration={markings, mark=between positions 0.05 and 1 step (1/10)*\pgfdecoratedpathlength with {\arrow{latex}}},
] {x};
\addplot[fill=blue!40] fill between[of=line and plot];
\end{axis}
\end{tikzpicture}
\end{document}