summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgfplots/libs/tikzlibrarypgfplots.groupplots.code.tex
blob: 32b0e5f32ee7dc7a236b5c9da94893d24face328 (plain)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
%--------------------------------------------
%
% 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 2009 by Nick Papior Andersen.
%
% 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/>.
%
%--------------------------------------------

\newif\ifpgfplots@group@sharedlabels

\def\pgfplots@group@xticklabels{}
\def\pgfplots@group@yticklabels{}
\def\pgfplots@group@xlabels{}
\def\pgfplots@group@ylabels{}
\def\pgfplots@group@totalplots{1}
\def\pgfplots@group@columns{1}
\def\pgfplots@group@rows{1}
\def\pgfplots@group@name{group}
\def\pgfplots@group@style{}
\gdef\pgfplots@group@rmopts{}
\newcount\pgfplots@group@current@plot
\newcount\pgfplots@group@current@row
\newcount\pgfplots@group@current@column

\usetikzlibrary{calc}

\pgfkeys{
    /pgfplots/group/.is family,
    /pgfplots/group style/.store in=\pgfplots@group@style,
    /pgfplots/group/horizontal sep/.initial=1cm,
    /pgfplots/group/vertical sep/.initial=1cm,
    /pgfplots/group/group size/.style args={#1 by #2}{/pgfplots/group/columns=#1,/pgfplots/group/rows=#2},
    /pgfplots/group/group size/.default={1 by 1},
    /pgfplots/group/columns/.store in=\pgfplots@group@columns,
    /pgfplots/group/rows/.store in=\pgfplots@group@rows,
    /pgfplots/group/every plot/.style=,
    /pgfplots/group/shared labels/.is if=pgfplots@group@sharedlabels,
    /pgfplots/group/shared labels=false,
    /pgfplots/group/xticklabels at/.is choice,
    /pgfplots/group/xticklabels at/all/.code=\def\pgfplots@group@xticklabels{all},
    /pgfplots/group/xticklabels at/edge top/.code=\def\pgfplots@group@xticklabels{top},
    /pgfplots/group/xticklabels at/edge bottom/.code=\def\pgfplots@group@xticklabels{lower},
    /pgfplots/group/xticklabels at/edge left/.code=\def\pgfplots@group@xticklabels{left}, % TODO
    /pgfplots/group/xticklabels at/edge right/.code=\def\pgfplots@group@xticklabels{right}, % TODO
    /pgfplots/group/xticklabels at=all,
    /pgfplots/group/yticklabels at/.is choice,
    /pgfplots/group/yticklabels at/all/.code=\def\pgfplots@group@yticklabels{all},
    /pgfplots/group/yticklabels at/edge left/.code=\def\pgfplots@group@yticklabels{left},
    /pgfplots/group/yticklabels at/edge right/.code=\def\pgfplots@group@yticklabels{right},
    /pgfplots/group/yticklabels at/edge top/.code=\def\pgfplots@group@yticklabels{top}, % TODO
    /pgfplots/group/yticklabels at/edge bottom/.code=\def\pgfplots@group@yticklabels{bottom}, % TODO
    /pgfplots/group/yticklabels at=all,
    /pgfplots/group/xlabels at/.is choice,
    /pgfplots/group/xlabels at/all/.code=\def\pgfplots@group@xlabels{all},
    /pgfplots/group/xlabels at/edge top/.code=\def\pgfplots@group@xlabels{top},
    /pgfplots/group/xlabels at/edge bottom/.code=\def\pgfplots@group@xlabels{lower},
    /pgfplots/group/xlabels at/edge right/.code=\def\pgfplots@group@xlabels{right}, % TODO
    /pgfplots/group/xlabels at/edge left/.code=\def\pgfplots@group@xlabels{left},% TODO
    /pgfplots/group/xlabels at=all,
    /pgfplots/group/ylabels at/.is choice,
    /pgfplots/group/ylabels at/all/.code=\def\pgfplots@group@ylabels{all},
    /pgfplots/group/ylabels at/edge left/.code=\def\pgfplots@group@ylabels{left},
    /pgfplots/group/ylabels at/edge right/.code=\def\pgfplots@group@ylabels{right},
    /pgfplots/group/ylabels at/edge top/.code=\def\pgfplots@group@ylabels{top}, % TODO
    /pgfplots/group/ylabels at/edge bottom/.code=\def\pgfplots@group@ylabels{bottom}, % TODO
    /pgfplots/group/ylabels at=all,
    /pgfplots/group/x descriptions at/.is choice,
    /pgfplots/group/x descriptions at/all/.style={
        /pgfplots/group/xlabels at=all,
        /pgfplots/group/xticklabels at=all
    },
    /pgfplots/group/x descriptions at/edge bottom/.style={
        /pgfplots/group/xlabels at=edge bottom,
        /pgfplots/group/xticklabels at=edge bottom
    },
    /pgfplots/group/x descriptions at/edge top/.style={
        /pgfplots/group/xlabels at=edge top,
        /pgfplots/group/xticklabels at=edge top
    },
    /pgfplots/group/y descriptions at/.is choice,
    /pgfplots/group/y descriptions at/all/.style={
        /pgfplots/group/ylabels at=all,
        /pgfplots/group/yticklabels at=all
    },
    /pgfplots/group/y descriptions at/edge left/.style={
        /pgfplots/group/ylabels at=edge left,
        /pgfplots/group/yticklabels at=edge left
    },
    /pgfplots/group/y descriptions at/edge right/.style={
        /pgfplots/group/ylabels at=edge right,
	/pgfplots/group/yticklabels at=edge right
    },
    /pgfplots/group/group name/.store in=\pgfplots@group@name,
    /pgfplots/group/empty plot/.style={/pgfplots/hide axis=true},
}

\def\nextgroupplot{%
    \pgfutil@ifnextchar[{\pgfplots@group@nextplot}{\pgfplots@group@nextplot[]}%}
}

%
% The actual addition of the new plots
%
\def\pgfplots@group@nextplot[#1]{%
    % Check if it legal to produce another plot
    \ifnum\pgfplots@group@current@plot=\pgfplots@group@totalplots\relax
      \pgfplots@warning{You are adding more plots than you specified, current plots=\the\pgfplots@group@current@plot\space vs. total allowed
          plots=\pgfplots@group@totalplots.}
    \else
      % 
      % If there has been other plots before then end the plot
      % 
      \ifnum0<\pgfplots@group@current@plot\relax
        % DEBUG: \message{DEBUG: Ending plot}
        \endpgfplots@environment@opt
      \fi
      % Prepare for next plot, increment plot, row and column
      \pgfplots@group@increment@numbers
      % DEBUG: \message{DEBUG: Cur. Plot: \the\pgfplots@group@current@plot. Current Row: \the\pgfplots@group@current@row. Current Column: \the\pgfplots@group@current@column.}    
      % Creation of the new axis environment
      \pgfplots@group@environment@create{#1}
    \fi
}
%
% This creates an environment according to which plots that have been typeset.
% The code utilizes previous plots anchor points to position themselves, unless it's the 
% first plot.
% Using the figure below to describe the code implementation:
% ____    ____   ____
%|        | |        | |        |
%|   1   | |   2   | |   3   |
%|___| |___| |___|
% ____    ____   ____
%|        | |        | |        |
%|   4   | |   5   | |   6   |
%|___| |___| |___|
% ____    ____   ____
%|        | |        | |        |
%|   7   | |   8   | |   9   |
%|___| |___| |___|
% 
% The plots anchors are as follows: 
%    1: plot is typeset normally
%    2: the "1" plot anchor "east" is anchored to "west"
%    3: the "2" plot anchor "east" is anchored to "west"
%    4: the "1" plot anchor "south" is anchored to "north"
%    5: the "2" plot anchor "south" is anchored to "north"
%    6: the "3" plot anchor "south" is anchored to "north"
%    7: the "4" plot anchor "south" is anchored to "north"
%    8: the "5" plot anchor "south" is anchored to "north"
%    9: the "6" plot anchor "south" is anchored to "north"
%
\def\pgfplots@group@environment@create#1{%
    \ifnum1=\pgfplots@group@current@row\relax
      \ifnum1=\pgfplots@group@current@column\relax
        \pgfplots@environment@opt[name={\pgfplots@group@name\space c\the\pgfplots@group@current@column r\the\pgfplots@group@current@row},%
          /pgfplots/group/every plot,%
          /pgfplots/group/plot c\the\pgfplots@group@current@column r\the\pgfplots@group@current@row,%
          #1]
      \else
        \pgfplotsgroupplotsmath@decrease\pgfplots@group@current@column
        \xdef\pgfplots@glob@TMPb{\pgfplots@group@name\space c\pgfmathresult r\the\pgfplots@group@current@row}
        \pgfplots@environment@opt[name={\pgfplots@group@name\space c\the\pgfplots@group@current@column r\the\pgfplots@group@current@row},%
          /pgfplots/group/every plot,%
          /pgfplots/group/plot c\the\pgfplots@group@current@column r\the\pgfplots@group@current@row,%
          at={($(\pgfplots@glob@TMPb.east)+(\pgfkeysvalueof{/pgfplots/group/horizontal sep},0)$)},anchor=west,%
          #1]
      \fi
    \else
      \pgfplotsgroupplotsmath@decrease\pgfplots@group@current@row
      \xdef\pgfplots@glob@TMPb{\pgfplots@group@name\space c\the\pgfplots@group@current@column r\pgfmathresult}
      \pgfplots@environment@opt[name={\pgfplots@group@name\space c\the\pgfplots@group@current@column r\the\pgfplots@group@current@row},%
        /pgfplots/group/every plot,%
        /pgfplots/group/plot c\the\pgfplots@group@current@column r\the\pgfplots@group@current@row,%
        at={($(\pgfplots@glob@TMPb.south)-(0,\pgfkeysvalueof{/pgfplots/group/vertical sep})$)},anchor=north,%
        #1]%
    \fi%
}

%
% Determine the labels of both x and y.
%
\def\pgfplots@group@determine@labels{%
    \def\pgfplots@loc@TMPa{all}
    \def\pgfplots@loc@TMPb{lower}
    \ifx\pgfplots@loc@TMPa\pgfplots@group@xlabels%
      % xlabels at=all
      % Do nothing as all should have xlabels
    \fi
    \gdef\pgfplots@glob@TMPa{}
    \ifx\pgfplots@loc@TMPb\pgfplots@group@xlabels%
	  % xlabels at=lower
      \ifnum1<\pgfplots@group@rows\relax
        \foreach \pgfplots@column in {1,...,\pgfplots@group@columns} {%
            \foreach \pgfplots@row in {1,...,\pgfplots@group@rows} {%
                \ifnum\pgfplots@row=\pgfplots@group@rows\relax%
                \else
                \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
                    \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/xlabel={}}}%
                \fi
            }%
        }%
      \fi%
	\else
		\def\pgfplots@loc@TMPb{top}%
		\ifx\pgfplots@loc@TMPb\pgfplots@group@xlabels%
			% xlabels at=top
			\ifnum1<\pgfplots@group@rows\relax
				\foreach \pgfplots@column in {1,...,\pgfplots@group@columns} {%
					\foreach \pgfplots@row in {1,...,\pgfplots@group@rows} {%
						\ifnum\pgfplots@row=1 %
						\expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
							\pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/xticklabel pos=upper}}%
						\else
						\expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
							\pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/xlabel={}}}%
						\fi
					}%
				}%
			\fi%
		\fi
    \fi
    % 
    % Defining styles for the y's
    % 
    \ifx\pgfplots@loc@TMPa\pgfplots@group@ylabels%
	  % ylabels at=all
      % Do nothing as all should have ylabels
	\else
		\def\pgfplots@loc@TMPb{left}%
		\ifx\pgfplots@loc@TMPb\pgfplots@group@ylabels%
			% ylabels at=left
			\ifnum1<\pgfplots@group@columns\relax
				\foreach \pgfplots@row in {1,...,\pgfplots@group@rows} {%
					\foreach \pgfplots@column in {2,...,\pgfplots@group@columns} {%
						\expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
							\pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/ylabel={}}}%
					}%
				}%
			\fi%
		\else
			\def\pgfplots@loc@TMPb{right}%
			\ifx\pgfplots@loc@TMPb\pgfplots@group@ylabels%
				% ylabels at=right
				\ifnum1<\pgfplots@group@columns\relax
					\foreach \pgfplots@row in {1,...,\pgfplots@group@rows} {%
						\foreach \pgfplots@column in {1,...,\pgfplots@group@columns} {%
							\ifnum\pgfplots@column=\pgfplots@group@columns\relax
							\expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
								\pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/yticklabel pos=upper}}%
							\else
							\expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
								\pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/ylabel={}}}%
							\fi
						}%
					}%
				\fi
			\fi%
		\fi
    \fi
    \expandafter\pgfkeys\expandafter{\pgfplots@glob@TMPa}
}

%
% Determine the ticklabels of both x and y.
%
\def\pgfplots@group@determine@ticklabels{%
    \def\pgfplots@loc@TMPa{all}
    \def\pgfplots@loc@TMPb{top}
    \def\pgfplots@loc@TMPc{lower}
    \ifx\pgfplots@loc@TMPa\pgfplots@group@xticklabels%
      % Do nothing as all should have xticklabels
    \fi
    \gdef\pgfplots@glob@TMPa{}
    \ifx\pgfplots@loc@TMPb\pgfplots@group@xticklabels%
      \foreach \pgfplots@column in {1,...,\pgfplots@group@columns} {%
          \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
              \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r1/.append style={xticklabel pos=upper}}%
          \ifnum1<\pgfplots@group@rows\relax
            \foreach \pgfplots@row in {2,...,\pgfplots@group@rows} {%
                \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
                    \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/xticklabels={}}}%
            }%
          \fi%
      }%
    \fi
    \ifx\pgfplots@loc@TMPc\pgfplots@group@xticklabels%
      \foreach \pgfplots@column in {1,...,\pgfplots@group@columns} {%
          \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
              \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@group@rows/.append style={xticklabel pos=lower}}%
          \ifnum1<\pgfplots@group@rows\relax
            \pgfplotsgroupplotsmath@decrease\pgfplots@group@rows
            \foreach \pgfplots@row in {1,...,\pgfmathresult} {%
                \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
                    \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/xticklabels={}}}%
            }%
          \fi%
      }%
    \fi%
    % 
    % Defining styles for the ytick's
    % 
    \def\pgfplots@loc@TMPb{left}
    \def\pgfplots@loc@TMPc{right}
    \ifx\pgfplots@loc@TMPa\pgfplots@group@yticklabels%
      % Do nothing as all should have yticklabels
    \fi
    \ifx\pgfplots@loc@TMPb\pgfplots@group@yticklabels%
      \foreach \pgfplots@row in {1,...,\pgfplots@group@rows} {%
          \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
              \pgfplots@glob@TMPa,/pgfplots/group/plot c1r\pgfplots@row/.append style={yticklabel pos=left}}%
          \ifnum1<\pgfplots@group@columns\relax
            \foreach \pgfplots@column in {2,...,\pgfplots@group@columns} {%
                \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
                    \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/yticklabels={}}}%
            }%
          \fi%
      }%
    \fi
    \ifx\pgfplots@loc@TMPc\pgfplots@group@yticklabels%
      \foreach \pgfplots@row in {1,...,\pgfplots@group@rows} {%
          \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
              \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@group@columns r\pgfplots@row/.append style={yticklabel pos=right}}%
          \ifnum1<\pgfplots@group@columns\relax
            \pgfplotsgroupplotsmath@decrease\pgfplots@group@columns
            \foreach \pgfplots@column in {1,...,\pgfmathresult} {%
                \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
                    \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.append style={/pgfplots/yticklabels={}}}%
            }%
          \fi%
      }%
    \fi%
    \expandafter\pgfkeys\expandafter{\pgfplots@glob@TMPa}
}

%
% The counters which are used to determine the current plot:
%    \pgfplots@group@current@plot
%    \pgfplots@group@current@column
%    \pgfplots@group@current@row
% gets incremented according to the scheme below:
% ____    ____   ____
%|        | |        | |        |
%|   1   | |   2   | |   3   |
%|___| |___| |___|
% ____    ____   ____
%|        | |        | |        |
%|   4   | |   5   | |   6   |
%|___| |___| |___|
% ____    ____   ____
%|        | |        | |        |
%|   7   | |   8   | |   9   |
%|___| |___| |___|
% where the number matches the plot number.
%
\def\pgfplots@group@increment@numbers{%
    \advance\pgfplots@group@current@plot by1
    \ifnum\pgfplots@group@current@column=\pgfplots@group@columns\relax
      \ifnum1=\pgfplots@group@current@plot\relax
      \else
        \advance\pgfplots@group@current@row by1
      \fi
      \pgfplots@group@current@column=1
    \else
      \advance\pgfplots@group@current@column by1
    \fi
}

\def\pgfplots@group@get@plot@name#1,#2\in#3{%
    \edef#3{c#1r#2}%
}


%
% Setting up all possible styles in current plot
% I.e. Setting:
% /pgfplots/group/plot c1r1/.style=
% /pgfplots/group/plot c2r1/.style=
% ...
% /pgfplots/group/plot c<columns>r<rows>/.style=
%
\def\pgfplots@group@individual@setup{%
    \gdef\pgfplots@glob@TMPa{}
    \foreach \pgfplots@column in {1,...,\pgfplots@group@columns} {%
        \foreach \pgfplots@row in {1,...,\pgfplots@group@rows} {%
            \expandafter\xdef\expandafter\pgfplots@glob@TMPa\expandafter{%
                \pgfplots@glob@TMPa,/pgfplots/group/plot c\pgfplots@column r\pgfplots@row/.style=}%
        }%
    }%
    \expandafter\pgfkeys\expandafter{\pgfplots@glob@TMPa}%
}



%
% Implementation of the environment {groupplots}
\def\pgfplots@environment@groupplot{%
	\pgfutil@ifnextchar[{\pgfplots@@environment@groupplot}{\pgfplots@@environment@groupplot[\pgfutil@empty]}%
}

\def\endpgfplots@environment@groupplot{\endpgfplots@environment@opt\endgroup}

\def\pgfplots@@environment@groupplot[#1]{%
    \begingroup%
    % Only find the keys column and row
    % the following things appear to be complete... ?
    \pgfkeysinstallkeyfilterhandler{/pgf/key filter handlers/append filtered to}{\pgfplots@group@rmopts}%
    \let\pgfplots@group@rmopts=\pgfutil@empty
    \pgfkeysinstallkeyfilter{/pgf/key filters/equals}{/pgfplots/group style}
    \pgfkeysinstallkeyfilter{/pgf/key filters/is descendant of}{/pgfplots/group}
    \pgfqkeysfiltered{/pgfplots}{#1}
    \edef\pgfplots@loc@TMPa{%
        \noexpand\pgfkeys{/pgfplots/group/.cd,\pgfplots@group@style}
    }\pgfplots@loc@TMPa
	%
	\let\pgfplots@set@options@sanitizemode@old=\pgfplots@set@options@sanitizemode
	\let\pgfplots@set@options@sanitize@old=\pgfplots@set@options@sanitize
	\let\pgfplots@set@options@sanitize=\relax
	\let\pgfplots@set@options@sanitizemode=\relax
    \expandafter\pgfplots@set@options\expandafter{\pgfplots@group@rmopts}
	\let\pgfplots@set@options@sanitize=\pgfplots@set@options@sanitize@old
	\let\pgfplots@set@options@sanitizemode=\pgfplots@set@options@sanitizemode@old
	%
    \pgfplots@group@individual@setup
    \pgfplots@group@determine@ticklabels
    \pgfplots@group@determine@labels
    \pgfplots@group@current@plot=0%
    \pgfplots@group@current@row=1%
    \pgfplots@group@current@column=0%
    \begingroup
      \c@pgf@counta=\pgfplots@group@rows\relax
      \multiply \c@pgf@counta by\pgfplots@group@columns\relax
      \edef\pgfmathresult{\the\c@pgf@counta}%
      \pgfmath@smuggleone\pgfmathresult
    \endgroup
    \edef\pgfplots@group@totalplots{\pgfmathresult}%
    %DEBUG: \message{TEST: \pgfplots@group@totalplots, rows=\pgfplots@group@rows, columns=\pgfplots@group@columns}%
}

% Assigns \pgfmathresult as #1-1 (in integer arithmetics)
%
% #1 an integer (a register or something which expands to an integer).
\def\pgfplotsgroupplotsmath@decrease#1{%
    \begingroup
      \c@pgf@counta=#1\relax
      \advance\c@pgf@counta by-1
      \edef\pgfmathresult{\the\c@pgf@counta}%
      \pgfmath@smuggleone\pgfmathresult
    \endgroup
}

\tikzaddtikzonlycommandshortcutlet\groupplot\pgfplots@environment@groupplot
\tikzaddtikzonlycommandshortcutlet\endgroupplot\endpgfplots@environment@groupplot

\endinput