1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
%--------------------------------------------
%
% Package pgfplots
%
% Provides a user-friendly interface to create function plots (normal
% plots, semi-logplots and double-logplots).
%
% It is based on Till Tantau's PGF package.
%
% Copyright 2013 by Christian Feuersaenger
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
%
%--------------------------------------------
% This library adds support for high-level instructions for "fill area
% between two arbitrary plots of functions".
%
% It activates the syntax
%
% \addplot fill between[of=A and B];
%
% where A and B are two plots named by 'name path='.
%
% In fact, this here is not much more than a low-level invocation of
% \pgfpathfillbetween
% and a couple of styles. It could become a TikZ library because it
% actually works on any two named paths, but it has its restrictions
% regarding the supported input paths: both need to be plots of
% functions (non-intersecting, should have at most one function value
% for each canvas X coord)
\pgfutil@IfUndefined{pgfplotsset}{%
\pgferror{Please load pgfplots before pgfplots.fillbetween.}%
\endinput
}{}%
\usetikzlibrary{fillbetween}
\usepgfplotslibrary{decorations.softclip}
\pgfkeys{
/pgfplots/every fill between plot/.style={/pgfplots/area legend,/tikz/fill},
/tikz/soft clip assign/domain/.code args={#1:#2}{%
\edef\pgfplots@loc@TMPa{(axis cs:#1,\pgfkeysvalueof{/pgfplots/ymin}) rectangle (axis cs:#2,\pgfkeysvalueof{/pgfplots/ymax})}%
\pgfkeysalso{/tikz/soft clip assign/path/.expand once=\pgfplots@loc@TMPa}%
},%
/tikz/soft clip assign/y domain y/.style={/tikz/soft clip assign/domain y={#1}},
/tikz/soft clip assign/domain y/.code args={#1:#2}{%
\edef\pgfplots@loc@TMPa{(axis cs:\pgfkeysvalueof{/pgfplots/xmin},#1) rectangle (axis cs:\pgfkeysvalueof{/pgfplots/xmax},#2)}%
\pgfkeysalso{/tikz/soft clip assign/path/.expand once=\pgfplots@loc@TMPa}%
},%
%
/pgfplots/execute at begin axis@@/.add={}{%
\gdef\pgfplotsfillbetween@list@of@layers@with@clippath{}%
\gdef\b@pgfplotsfillbetween@list@has@set@layers{0}%
},
}
\def\pgfplotsfillbetween@ensure@clipping@on@layer{%
\ifpgfplots@clip
\pgfkeysgetvalue{/tikz/fill between/on layer}\pgfplots@loc@TMPa
\edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa}%
%
% check if 'pre main,' is inside of the already prepared layers:
\def\pgfplots@loc@TMPb{\expandafter\pgfutil@in@\expandafter{\pgfplots@loc@TMPa,}}%
\expandafter\pgfplots@loc@TMPb\expandafter{\pgfplotsfillbetween@list@of@layers@with@clippath}%
%
\ifpgfutil@in@
% ah - already prepared. Good, nothing left to do.
\else
\pgfplots@log3{fill between: found 'clip=true'. installing clip path for layer '\pgfplots@loc@TMPa'...}%
\xdef\pgfplotsfillbetween@list@of@layers@with@clippath{\pgfplots@loc@TMPa,\pgfplotsfillbetween@list@of@layers@with@clippath}%
%
\edef\pgfplots@loc@TMPb{%
\noexpand\pgfplotsextra{%
\noexpand\pgfplotsonlayer{\pgfplots@loc@TMPa}%
\noexpand\pgfplotspathaxisoutline
\noexpand\pgfusepath{clip}%
\noexpand\endpgfplotsonlayer
}%
}%
\pgfplots@loc@TMPb
%
\fi
\fi
}%
% The options are from
% \addplot[#1] fill between[#2] #3;
%
% This method is invoked from the global \addplot dispatching.
\def\pgfplotslibraryfillbetween@addplot#1#2#3{%
%
\pgfplots@start@plot@with@behavioroptions{/pgfplots/every fill between plot,#1}%
%
\pgfkeysvalueof{/pgfplots/execute at end survey}%
\pgfplots@remember@survey@option@list
%
%
\pgfplotslibraryfillbetweenpreparecurrentlayer
%
\pgfplots@addplot@enqueue@coords{%
% precmd
}{%
% empty - this here is a TikZ instruction, not a "real" \addplot command
}{%
% the path instruction:
\tikzfillbetween[#2]{%
/pgfplots/.search also=/tikz,%
/pgfplots/.cd,%
#1%
}%
}{%
% post command.
}%
}
% SIDE-EFFECT: modifies \b@pgfplotsfillbetween@list@has@set@layers and
% \pgfplotsfillbetween@list@of@layers@with@clippath
\def\pgfplotslibraryfillbetweenpreparecurrentlayer{%
\pgfkeysgetvalue{/tikz/fill between/on layer}\pgfplots@loc@TMPa
\ifx\pgfplots@loc@TMPa\pgfutil@empty
\else
\if0\b@pgfplotsfillbetween@list@has@set@layers
\pgfplots@log3{fill between: activating layered graphics}%
\pgfplotssetlateoptions{set layers}%
\gdef\b@pgfplotsfillbetween@list@has@set@layers{1}%
\fi
\pgfplotsfillbetween@ensure@clipping@on@layer
\fi
}
\def\pgfplots@tikzfillbetween{\pgfutil@ifnextchar[{\pgfplots@tikzfillbetween@opt}{\pgfplots@tikzfillbetween@opt[]}}
\def\pgfplots@tikzfillbetween@opt[#1]#2{%
\pgfplots@addplot@enqueue@coords{%
% precmd
}{%
% empty - this here is a TikZ instruction, not a "real" \addplot command
}{%
% the path instruction:
\tikzfillbetween[#1]{#2}%
}{%
% post command.
}%
}%
\expandafter\def\expandafter\pgfplots@replace@path@commands\expandafter{\pgfplots@replace@path@commands
\let\pgfplots@orig@tikzfillbetween=\tikzfillbetween
\let\tikzfillbetween=\pgfplots@tikzfillbetween
}%
\expandafter\def\expandafter\pgfplots@restore@path@commands\expandafter{\pgfplots@restore@path@commands
\let\tikzfillbetween=\pgfplots@orig@tikzfillbetween
}
\endinput
|