
環境では2 つのパスgroupplot
を使用する必要があり、これらのパスの 1 つには軸上にあるマーカーがあります。これらのマーカーをクリップしたいのですが、最初のパスが空と見なされるため、fill between
問題が発生します。fill between
マーカーをクリップして使用するにはどうすればいいですかfill between
?
MWE は下記に示されています。問題を明確に確認するには、コメント行のclip marker paths=true,
オン/オフを切り替えることができます。コメントが解除されている場合、問題はここにあります。
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, pgfplots.groupplots}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size=2 by 1}, scale only axis,
% clip marker paths=true,
axis on top=true]
% Plot main figure (a)
\nextgroupplot[scale only axis,
xmin=0,
xmax=100,
ymin=0,
ymax=550]
\addplot[name path = pathA, color=blue, mark=square*] coordinates {(0,250)(100,450)};
\path[name path = pathAxis] (axis cs:0,0) -- (axis cs:100,0);
\addplot [gray!30] fill between[of = pathA and pathAxis, soft clip = {domain=20:50}];
\nextgroupplot[scale only axis, restrict y to domain=190:240]
\end{groupplot}
\end{tikzpicture}
\end{document}
答え1
これは単なる回避策です。プロットを 2 回追加します。1 回は非表示にして塗りつぶしに使用できるようにし、もう 1 回は「実際に」追加します。(クリップなどで少し実験してみましたが、この回避策よりもエレガントなものはなかったので、投稿します。もちろん、よりエレガントな解決策があることを願っています。)
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, pgfplots.groupplots}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size=2 by 1}, scale only axis,
axis on top=true]
% Plot main figure (a)
\nextgroupplot[scale only axis,clip marker paths=true,
xmin=0,
xmax=100,
ymin=0,
ymax=550]
\addplot[color=blue, mark=square*] coordinates {(0,250)(100,450)};
\addplot[name path = pathA,draw=none,no marks,forget plot] coordinates {(0,250)(100,450)};
\path[name path = pathAxis] (axis cs:0,0) -- (axis cs:100,0);
\addplot [gray!30] fill between[of = pathA and pathAxis, soft clip = {domain=20:50}];
\nextgroupplot[scale only axis, restrict y to domain=190:240]
\end{groupplot}
\end{tikzpicture}
\end{document}