使用存在于组图生成组图并填充曲线之间为散点图生成的曲线下的区域着色,我在输出时遇到了问题。它总是用白色填充图表区域。以下是示例代码
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.10}
\usetikzlibrary{pgfplots.groupplots}
%\pgfplotsset{plot coordinates/math parser=false}
\makeatletter
\pgfplotsset{
groupplot xlabel/.initial={},
every groupplot x label/.style={
at={($({group c1r\pgfplots@[email protected]}|-{group c1r\pgfplots@[email protected] south})!0.5!({group c\pgfplots@group@columns r\pgfplots@[email protected]}|-{group c\pgfplots@group@columns r\pgfplots@[email protected] south})$)},
anchor=north,
},
groupplot ylabel/.initial={},
every groupplot y label/.style={
rotate=0,
at={($({group c1r1.north}-|{group c1r1.outer
west})!0.5!({group c1r\pgfplots@[email protected]}-|{group c1r\pgfplots@[email protected] west})$)},
anchor=east
},
execute at end groupplot/.code={%
\node [/pgfplots/every groupplot x label]
{\pgfkeysvalueof{/pgfplots/groupplot xlabel}};
\node [/pgfplots/every groupplot y label]
{\pgfkeysvalueof{/pgfplots/groupplot ylabel}};
},
group/only outer labels/.style =
{
group/every plot/.code = {%
\ifnum\pgfplots@group@current@row=\pgfplots@group@rows\else%
\pgfkeys{xticklabels = {}, xlabel = {}}\fi%
\ifnum\pgfplots@group@current@column=1\else%
\pgfkeys{yticklabels = {}, ylabel = {}}\fi%
}
}
}
\def\endpgfplots@environment@groupplot{%
\endpgfplots@environment@opt%
\pgfkeys{/pgfplots/execute at end groupplot}%
\endgroup%
}
\makeatother
\begin{filecontents}{data.dat}
sat1 etc1 sat2 etc2 sat3 etc3 sat4 etc4
0 0.06 0 0.10 0 0.17 0 0.25
10 0.09 10 0.15 10 0.23 10 0.31
20 0.13 20 0.22 20 0.30 20 0.37
30 0.15 30 0.27 30 0.36 30 0.43
40 0.17 40 0.31 40 0.42 40 0.49
50 0.19 50 0.31 50 0.46 50 0.53
60 0.20 60 0.32 60 0.47 60 0.54
70 0.22 70 0.33 70 0.48 70 0.55
80 0.24 80 0.34 80 0.49 80 0.56
90 0.25 90 0.35 90 0.50 90 0.57
100 0.27 100 0.35 100 0.51 100 0.58
\end{filecontents}
\begin{document}
\pgfplotstableread{data.dat}{\1}
\begin{tikzpicture}
\pgfplotsset{%
label style={font=\scriptsize},
tick label style={font=\scriptsize},
axis line style={<->},
width=4cm,
height=4cm,
scale only axis
}
\begin{groupplot}[%
group style={group size=2 by 1,
horizontal sep=5pt,
vertical sep=5pt},
xtick={0,10,20,30,40,50,60,70,80,90},
xticklabels={0,10,20,30,40,50,60,70,80,90},
yticklabels={0,0.1,0.2,0.3,0.4,0.5,0.6},
ytick={0,0.1,0.2,0.3,0.4,0.5,0.6},
groupplot ylabel={Y label},
groupplot xlabel={X label},
group/only outer labels
% legend style={legend cell align=right,legend plot pos=right}
]
% ROW 1
\nextgroupplot[
xmin=0,
xmax=100,
ymin=0,
ymax=0.6,
title=\textbf{$\phi=25\%$},every axis title/.style={below right,at={(0,1)},draw=black,fill=white}
]
\addplot+ [smooth,blue,name path=A] table[x={sat4}, y={etc4}] {\1};
\addplot+[draw=none,name path=B, domain=1:50, mark=none] {1};
\addplot+[gray, fill opacity=0.4] fill between[of=A and B,soft clip={domain=1:50}];
\nextgroupplot[
% ylabel={E=10 GPa},
xmin=0,
xmax=100,
ymin=0,
ymax=0.6,
title=\textbf{$\phi=30\%$},every axis title/.style={below right,at={(0,1)},draw=black,fill=white}
]
\addplot+ [smooth,blue,name path=A] table[x={sat3}, y={etc3}] {\1};
\addplot+[draw=none,name path=B, domain=1:50, mark=none] {1};
\addplot+[gray, fill opacity=0.4] fill between[of=A and B,soft clip={domain=1:50}];
\makeatletter
\end{groupplot}
\end{tikzpicture}
\end{document}
我认为似乎存在一个我无法解决的分层问题。也欢迎不使用填充之间的其他建议。
答案1
我认为这不是你希望的解决方案,但至少你得到了一个可行的结果。有关更多详细信息,请查看代码中的注释。
% used PGFPlots v1.15
\begin{filecontents}{data.dat}
sat1 etc1 sat2 etc2 sat3 etc3 sat4 etc4
0 0.06 0 0.10 0 0.17 0 0.25
10 0.09 10 0.15 10 0.23 10 0.31
20 0.13 20 0.22 20 0.30 20 0.37
30 0.15 30 0.27 30 0.36 30 0.43
40 0.17 40 0.31 40 0.42 40 0.49
50 0.19 50 0.31 50 0.46 50 0.53
60 0.20 60 0.32 60 0.47 60 0.54
70 0.22 70 0.33 70 0.48 70 0.55
80 0.24 80 0.34 80 0.49 80 0.56
90 0.25 90 0.35 90 0.50 90 0.57
100 0.27 100 0.35 100 0.51 100 0.58
\end{filecontents}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\usepackage{filecontents}
\usetikzlibrary{
pgfplots.fillbetween,
pgfplots.groupplots,
}
\pgfplotsset{
% use this `compat' level or higher so TikZ coordinates don't have to be
% prefixed by `axis cs:'
compat=1.11,
% plot coordinates/math parser=false,
}
\makeatletter
\pgfplotsset{
groupplot xlabel/.initial={},
every groupplot x label/.style={
at={
($ ({group c1r\pgfplots@[email protected]}
|-{group c1r\pgfplots@[email protected] south})%
!0.5!%
({group c\pgfplots@group@columns r\pgfplots@[email protected]}%
|-{group c\pgfplots@group@columns r\pgfplots@[email protected] south}) $)
},
anchor=north,
},
groupplot ylabel/.initial={},
every groupplot y label/.style={
rotate=0,
at={
($ ({group c1r1.north}-|{group c1r1.outer west})%
!0.5!%
({group c1r\pgfplots@[email protected]}%
-|{group c1r\pgfplots@[email protected] west}) $)
},
anchor=east,
},
execute at end groupplot/.code={%
\node [/pgfplots/every groupplot x label]
{\pgfkeysvalueof{/pgfplots/groupplot xlabel}};
\node [/pgfplots/every groupplot y label]
{\pgfkeysvalueof{/pgfplots/groupplot ylabel}};
},
group/only outer labels/.style={
group/every plot/.code = {%
\ifnum\pgfplots@group@current@row=\pgfplots@group@rows\else%
\pgfkeys{xticklabels = {}, xlabel = {}}\fi%
\ifnum\pgfplots@group@current@column=1\else%
\pgfkeys{yticklabels = {}, ylabel = {}}\fi%
},
},
}
% % ---------------------------------------------------------------------
% % is it intended that these lines cause the axis lines to not be drawn?
% % This is also one of the causes why the `fill between' stuff isn't drawn.
% \def\endpgfplots@environment@groupplot{%
% \endpgfplots@environment@opt%
% \pgfkeys{/pgfplots/execute at end groupplot}%
% \endgroup%
% }
% % ---------------------------------------------------------------------
\makeatother
\pgfplotstableread{data.dat}{\1}
\pgfplotsset{
label style={font=\scriptsize},
tick label style={font=\scriptsize},
axis line style={<->},
width=4cm,
height=4cm,
scale only axis,
}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group size=2 by 1,
horizontal sep=5pt,
vertical sep=5pt,
},
xtick={0,10,20,30,40,50,60,70,80,90},
ytick={0,0.1,0.2,0.3,0.4,0.5,0.6},
% (moved here)
every axis title/.style={
below right,
at={(0,1)},
draw=black,
fill=white,
},
% ---------------------------------------------------------------------
groupplot ylabel={Y label},
groupplot xlabel={X label},
group/only outer labels,
%
% instead of using the above custom keys you can also force the
% ticklabels to be drawn only on the left and bottom with
group/xticklabels at=edge bottom,
group/yticklabels at=edge left,
% ---------------------------------------------------------------------
]
% ROW 1
\nextgroupplot[
xmin=0,
xmax=100,
ymin=0,
ymax=0.6,
title=\textbf{$\phi=25\%$},
]
\addplot+ [smooth,blue,name path=A] table [x={sat4}, y={etc4}] {\1};
% you didn't follow the solution given at
% <https://tex.stackexchange.com/a/283533>
% so changing the constant from 1 to 0.6 in the following `\addplot'
% command would work, but then you have to keep this in sync with the
% `ymax' value ...
% \addplot+[draw=none,name path=B, domain=1:50, mark=none] {0.6};
% ... so I suggest doing this
\path [name path=B]
(\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/ymax}) --
(\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/ymax});
\addplot+ [gray, fill opacity=0.4] fill between [of=A and B,soft clip={domain=1:50}];
\nextgroupplot[
xmin=0,
xmax=100,
ymin=0,
ymax=0.6,
title=\textbf{$\phi=30\%$},
]
\addplot+ [smooth,blue,name path=A] table [x={sat3}, y={etc3}] {\1};
\path [name path=B]
(\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/ymax}) --
(\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/ymax});
\addplot+ [gray, fill opacity=0.4] fill between [of=A and B,soft clip={domain=1:50}];
\end{groupplot}
% add axis labels
\node [
% red,
anchor=north,
]
at ($ (group c1r1.below south west)!0.5!(group c2r1.below south east) $)
{X label};
\node [
% red,
anchor=east,
]
at ($ (group c1r1.left of north west)!0.5!(group c1r1.left of south west) $)
{Y label};
\end{tikzpicture}
\end{document}