Debian Codegraph @

texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex

raw
1 %--------------------------------------------
2 % $Header: /cvsroot/pgfplots/pgfplots/generic/pgfplots/util/pgfplotscolormap.code.tex,v 1.15 2009/07/21 18:18:48 ludewich Exp $
3 %
4 % Package pgfplots
5 %
6 % Provides a user-friendly interface to create function plots (normal
7 % plots, semi-logplots and double-logplots).
8 %
9 % It is based on Till Tantau's PGF package.
10 %
11 % Copyright 2007-2013 by Christian Feuersänger.
12 %
13 % This program is free software: you can redistribute it and/or modify
14 % it under the terms of the GNU General Public License as published by
15 % the Free Software Foundation, either version 3 of the License, or
16 % (at your option) any later version.
17 %
18 % This program is distributed in the hope that it will be useful,
19 % but WITHOUT ANY WARRANTY; without even the implied warranty of
20 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 % GNU General Public License for more details.
22 %
23 % You should have received a copy of the GNU General Public License
24 % along with this program. If not, see <http://www.gnu.org/licenses/>.
25 %
26 %--------------------------------------------
27
28 \input pgfplotscolor.code.tex
29
30 \pgfkeyssetvalue{/pgfplots/colormap default colorspace}{auto}
31
32 % preset for '/pgfplots/colormap uniform=always
33 % This is only used for the colormap predefined in this very file.
34 \def\pgfplots@colormap@uniform@choice{0}%
35
36 % This package relies on pgfplots temporary registers and its array
37 % data structure.
38
39 % Internal structure:
40 % the colormap data structure consists of
41 % - an array 'pgfpl@cm@#1' of RGB color triples,
42 % - numbers 'pgfpl@cm@#1@h' and 'pgfpl@cm@#1@invh' for the mesh width
43 % and inverse mesh width.
44
45 % Creates a new colormap.
46 %
47 % #1 : the name of the color map as string (not as macro).
48 % #2 : a <color specification> as is expected for a shading spec of
49 % pgf. However, the format allows a little bit more freedom:
50 % - it supports 'rgb255' in addition to pgf,
51 % - the length is not required (defaults to 1cm for the first and to
52 % the last length+h for all others).
53 % - the semicolons can be omitted.
54 %
55 % Example:
56 % \pgfplotscreatecolormap{my map}{rgb(0cm)=(1,0,0); rgb(1cm)=(0,1,0); rgb255(1.5cm)=(128,5,255); rgb(2cm)=(0,0,1); gray(3cm)=(3); color(4cm)=(green); }
57 % \pgfplotscreatecolormap{my map}{color=(green); color=(red); color=(blue); color=(yellow)}
58 \def\pgfplotscreatecolormap#{\pgfplots@createcolormap}%
59 \def\pgfplots@createcolormap#1#2{%
60 \pgfkeysinterruptkeyfilter
61 \edef\pgfplots@createcolormap@name{pgfpl@cm@#1}%
62 \expandafter\pgfplotsarraynewempty\expandafter{\pgfplots@createcolormap@name}%
63 \pgfplotsapplistXnewempty\pgfplots@createcolormap@X
64 %
65 % '0' = is not uniform
66 % '1' = is uniform
67 % '2' = is FORCED to be uniform, i.e. will be reinterpolated
68 \ifcase\pgfplots@colormap@uniform@choice\relax
69 % colormap uniform=always (due to compatibility requirements)
70 \def\b@pgfplotscreatecolormap@isuniform{2}%
71 \or
72 % colormap uniform=if requested
73 \def\b@pgfplotscreatecolormap@isuniform{1}%
74 \fi
75 \def\pgfplots@createcolormap@MIN{}% To be computed.
76 \def\pgfplots@createcolormap@MAX{}% To be computed.
77 \def\b@pgfplots@createcolormap@pos@mode{a}% [a]uto or [m]anual
78 \pgfplots@createcolormap@initcolorspace
79 \let\pgfplots@createcolormap@LAST=\pgfplots@createcolormap@MIN
80 % PARSE IT:
81 \let\pgfplots@createcolormap@context=\pgfutil@empty
82 %%%%%%%%%%%%%%%%%%
83 % this does also init @H:
84 \pgflibraryfpuifactive{%
85 \def\pgfplots@createcolormap@restore@fpu{}%
86 }{%
87 \def\pgfplots@createcolormap@restore@fpu{\pgfkeys{/pgf/fpu=false}}%
88 \pgfkeys{/pgf/fpu=true}%
89 }%
90 %\edef\pgfplots@loc@TMPa{#2}% XXX this fails for active chars and
91 %if key/value options are too special
92 \def\pgfplots@loc@TMPa{#2}%
93 \expandafter\pgfplots@createcolormap@startloop\pgfplots@loc@TMPa\pgfplots@EOI
94 %
95 \pgfplots@createcolormap@restore@fpu
96 %
97 %%%%%%%%%%%%%%%%%%
98 %
99 \expandafter\pgfplotsarraycheckempty\expandafter{\pgfplots@createcolormap@name}%
100 % sanity checking:
101 \expandafter\pgfplotsarraysizetomacro\expandafter{\pgfplots@createcolormap@name}\to\pgfplots@loc@TMPa
102 \ifcase\pgfplots@loc@TMPa\relax
103 \pgfplots@error{Sorry, you need to provide at least two points of a colormap.}%
104 \or
105 \pgfplots@error{Sorry, you need to provide at least two points of a colormap.}%
106 \fi
107 % Map the input range [MIN,MAX] linearly to [0,1000]
108 \pgfmathfloatsubtract@{\pgfplots@createcolormap@MAX}{\pgfplots@createcolormap@MIN}%
109 \let\pgfplots@loc@TMPb=\pgfmathresult
110 \pgfmathfloatdivide@{\pgfplotscolormaprange@float}{\pgfplots@loc@TMPb}%
111 \let\pgfplots@loc@TMPb=\pgfmathresult
112 \pgfmathfloatmultiply@{\pgfplots@loc@TMPb}{\pgfplots@createcolormap@H}%
113 \let\pgfplots@loc@TMPd=\pgfmathresult
114 \pgfplots@createcolormap@normalize{\pgfmathresult}%
115 \expandafter\let\csname\pgfplots@createcolormap@name @h\endcsname=\pgfmathresult
116 %
117 \pgfmathfloatreciprocal@{\pgfplots@loc@TMPd}%
118 \pgfplots@createcolormap@normalize{\pgfmathresult}%
119 \expandafter\let\csname\pgfplots@createcolormap@name @invh\endcsname=\pgfmathresult
120 %
121 % ... and set up the X coordinates if the grid is not uniform:
122 \expandafter\pgfplotsarraynewempty\expandafter{\pgfplots@createcolormap@name @X}%
123 \if0\b@pgfplotscreatecolormap@isuniform
124 % Uncomment the '\iftrue' for testing purposes (to see if a uniform map changes if
125 % processed as non-uniform):
126 % \iftrue
127 \pgfplotsapplistXlet\pgfplots@loc@TMPc=\pgfplots@createcolormap@X
128 \expandafter\pgfplotsutilforeachcommasep\expandafter{\pgfplots@loc@TMPc}\as\pgfplots@loc@TMPc{%
129 \ifx\pgfplots@loc@TMPc\pgfutil@empty
130 \else
131 % apply the trafo [MIN,MAX] -> [0,1000] here as well:
132 \pgfmathfloatsubtract@{\pgfplots@loc@TMPc}{\pgfplots@createcolormap@MIN}%
133 \expandafter\pgfmathfloatmultiply@\expandafter{\pgfmathresult}{\pgfplots@loc@TMPb}%
134 \pgfplots@createcolormap@normalize{\pgfmathresult}%
135 \expandafter\pgfplotsarraypushback\expandafter{\pgfmathresult}\to{pgfpl@cm@#1@X}%
136 \fi
137 }%
138 %
139 \pgfplotscolormapsetadditionalintervalwidth@{#1}%
140 \else
141 \expandafter\let\csname\pgfplots@createcolormap@name @X@scale@order@z\endcsname=\pgfutil@empty
142 \fi
143 % clear temporary list:
144 \pgfplotsapplistXnewempty\pgfplots@createcolormap@X
145 %
146 \if m\b@pgfplots@createcolormap@pos@mode
147 % Ah - we have manually provided positions!
148 % DISABLE the extra interval. You have to enable it explicitly
149 % by means of 'colormap access/extra interval width=0.1'
150 \expandafter\def\csname\pgfplots@createcolormap@name @X@scale@order@z\endcsname{0}%
151 \fi
152 %
153 \endpgfplotscolornormalizesequence%
154 \expandafter\let\csname\pgfplots@createcolormap@name @colspace\endcsname=\pgfplotsretval
155 \expandafter\let\csname\pgfplots@createcolormap@name @col@comps\endcsname=\pgfplotsretvalb
156 \c@pgf@counta=\expandafter\pgfplotsarraysizeof\expandafter{\pgfplots@createcolormap@name}\relax
157 \advance\c@pgf@counta by-1 %
158 \expandafter\edef\csname\pgfplots@createcolormap@name @lastindex\endcsname{\the\c@pgf@counta}%
159 %\pgfplots@colormap@showdebuginfofor{#1}%
160 \pgfplots@colormap@LUA@new{#1}%
161 \endpgfkeysinterruptkeyfilter
162 }
163
164 \def\pgfplots@createcolormap@normalize#1{%
165 \pgfmathfloattofixed{#1}%
166 \pgf@xa=\pgfmathresult pt %
167 \edef\pgfmathresult{\pgf@sys@tonumber\pgf@xa}% normalize number.
168 }%
169
170 % Allows to customize the width of the additional interval used for
171 % 'colormap access=piecewise constant'.
172 %
173 % #1 colormap name
174 % #2 the additional interval width for this colormap. Use '0' to disable the additional
175 % interval. The value is relative to the total width and must be in
176 % the range 0<=#2<=0.9
177 \def\pgfplotscolormapsetadditionalintervalwidth#1#2{%
178 \edef\pgfplots@loc@TMPd{#2}%
179 \def\pgfplots@loc@TMPc{h}%
180 \ifx\pgfplots@loc@TMPd\pgfplots@loc@TMPc
181 % 'h' means: mesh width:
182 \pgfplotscolormapifisuniform{#1}{%
183 \expandafter\let\csname pgfpl@cm@#1@X@scale@order@z\endcsname\pgfutil@empty%
184 }{%
185 \pgfplotscolormapsetadditionalintervalwidth@{#1}%
186 }%
187 \else
188 \pgfmathparse{#2}%
189 \pgfplotscolormapifisuniform{#1}{%
190 \ifdim\pgfmathresult pt>0pt
191 \pgfplots@error{Uniform colormaps support no configuration of the additional interval width for a colormap (although you can use 0 to turn it off). Please use a non-uniform colormap.}%
192 \else
193 % DISABLE the extra interval!
194 \expandafter\def\csname pgfpl@cm@#1@X@scale@order@z\endcsname{0}%
195 \fi
196 }{%
197 \ifdim\pgfmathresult pt>0pt
198 \ifdim\pgfmathresult pt>0.9pt
199 \pgfplots@error{Expected a number 0< X <= 0.9, not \pgfmathresult}%
200 \else
201 % compute the 'h'.
202 %
203 % Note that 's:=#2' is a fraction 0<x<1 of the RESULTING
204 % range, i.e. s * 1000 = H where 0<=H<=1000.
205 % but H = 1000/(1000+h) * 1000, and we need the 'h'.
206 %
207 % -> h = 1000/s - 1000.
208 % regarding the '1-#2': I did some mistake in my
209 % computation and that fixed it :-/
210 \pgfmathparse{1000/(1-#2)-1000}%
211 \expandafter\let\csname pgfpl@cm@#1@h\endcsname=\pgfmathresult
212 \expandafter\let\csname pgfpl@cm@#1@invh\endcsname=\pgfutil@empty% unused!
213 \pgfplotscolormapsetadditionalintervalwidth@{#1}%
214 \fi
215 \else
216 % DISABLE the extra interval!
217 \expandafter\def\csname pgfpl@cm@#1@X@scale@order@z\endcsname{0}%
218 \fi
219 }%
220 \fi
221 %
222 \ifpgfplots@LUA@supported
223 \pgfplotsutil@directlua{%
224 pgfplots.texColorMapSetScaleOrderZ("#1", "\csname pgfpl@cm@#1@X@scale@order@z\endcsname")
225 }%
226 \fi
227 }%
228
229 % see \pgfplotscolormapsetadditionalintervalwidth
230 \def\pgfplotscolormapsetadditionalintervalwidth@#1{%
231 % 'colormap access=piecewise constant' (order 0) requires a
232 % special scaling factor. See its consumers for details +
233 % documentation
234 \pgfmathparse{1000/(1000+\csname pgfpl@cm@#1@h\endcsname)}%
235 \expandafter\let\csname pgfpl@cm@#1@X@scale@order@z\endcsname=\pgfmathresult
236 }%
237
238 \def\pgfplots@createcolormap@initcolorspace{%
239 \pgfplotscolornormalizesequence[
240 colorspace=\pgfkeysvalueof{/pgfplots/colormap default colorspace},
241 context message=\pgfplots@createcolormap@context\pgfplots@createcolormap@trace,
242 ]%
243 }%
244 \def\pgfplots@createcolormap@seth[#1]{%
245 \def\pgfplots@createcolormap@context{[#1]}%
246 \pgfmathparse{#1}%
247 \let\pgfplots@createcolormap@H=\pgfmathresult
248 % request for a uniform colormap:
249 \def\b@pgfplotscreatecolormap@isuniform{3}%
250 \pgfplots@createcolormap@
251 }%
252
253 \def\pgfplots@createcolormap@startloop{%
254 \pgfutil@ifnextchar[%
255 {\pgfplots@createcolormap@seth}%
256 {%
257 \let\pgfplots@createcolormap@H=\pgfutil@empty
258 \pgfplots@createcolormap@
259 }%
260 }%
261 \def\pgfplots@createcolormap@{%
262 \pgfutil@ifnextchar\pgfplots@EOI{\pgfutil@gobble}%done!
263 {%
264 \pgfutil@ifnextchar;{\pgfplots@createcolormap@grabsemicolon}%
265 {%
266 \pgfutil@ifnextchar,{\pgfplots@createcolormap@grabcomma}%
267 {%
268 \expandafter\pgfutil@ifnextchar\pgfplots@activesemicolon{\pgfplots@createcolormap@grabsemicolon@active}%
269 {%
270 \pgfplots@createcolormap@grabnext
271 }%
272 }%
273 }%
274 }%
275 }
276
277 % Executes '#1' if there are more tokens and '#2' if not.
278 \def\pgfplots@createcolormap@ifhasmorecolors#1#2{%
279 \pgfutil@ifnextchar\pgfplots@EOI{%
280 #2% no more tokens.
281 }{%
282 \pgfutil@ifnextchar;{\pgfplots@createcolormap@grabsemicolon@hasnext{#1}{#2}}%
283 {%
284 \pgfutil@ifnextchar,{\pgfplots@createcolormap@grabcomma@hasnext{#1}{#2}}%
285 {%
286 \expandafter\pgfutil@ifnextchar\pgfplots@activesemicolon{\pgfplots@createcolormap@grabsemicolon@active@hasnext{#1}{#2}}%
287 {%
288 #1% has more.
289 }%
290 }%
291 }%
292 }%
293 }%
294
295 \def\pgfplots@createcolormap@error#1#2\pgfplots@EOI{%
296 {%
297 \t@pgfplots@toka={#1#2}%
298 \t@pgfplots@tokb={#1}%
299 \pgfplots@error{Illformed colormap specification: I could not read the substring `\the\t@pgfplots@toka' starting at `\the\t@pgfplots@tokb'\pgfplots@createcolormap@trace}%
300 }%
301 }%
302
303 \def\pgfplots@createcolormap@trace{%
304 \space(color no \expandafter\pgfplotsarraysizeof\expandafter{\pgfplots@createcolormap@name})
305 }
306
307 \def\pgfplots@createcolormap@grabnext#1={%
308 \pgfutil@ifnextchar({\pgfplots@createcolormap@grabnext@round{#1}=}{%
309 \pgfutil@ifnextchar\bgroup{\pgfplots@createcolormap@grabnext@curly{#1}=}{%
310 \pgfplots@createcolormap@error#1=%
311 }%
312 }%
313 }
314 \def\pgfplots@createcolormap@grabnext@round#1=(#2){%
315 \pgfplots@createcolormap@grabnext@@{#1}={#2}%
316 }%
317 \def\pgfplots@createcolormap@grabnext@curly#1=#2{%
318 \pgfplots@createcolormap@grabnext@@{#1}={#2}%
319 }%
320 \def\pgfplots@createcolormap@grabnext@@#1=#2{%
321 \pgfutil@in@({#1}%
322 \ifpgfutil@in@
323 % Ah. We have something like 'color(1cm)' before the equal sign.
324 \pgfplots@createcolormap@grabnext@read@pos#1\pgfplots@EOI%
325 % now:
326 %\pgfplots@loc@TMPa = colorspace
327 %\pgfplots@loc@TMPb = position
328 %
329 \else
330 % Ah. we do not have a position, i.e. we have
331 % color=(green)
332 % or something like this.
333 %
334 % this here defines \pgfplots@loc@TMPa to contain the
335 % colorspace:
336 \pgfkeys@spdef\pgfplots@loc@TMPa{#1}%
337 %
338 \pgfplots@createcolormap@grabnext@computenextposition
339 \let\pgfplots@loc@TMPb=\pgfmathresult% position
340 \fi
341 \def\pgfplots@loc@TMPc{#2}%
342 \pgfplots@createcolormap@grabnext@complete
343 }%
344
345 \def\pgfplots@createcolormap@grabnext@read@pos#1({%
346 \pgfkeys@spdef\pgfplots@loc@TMPa{#1}% colorspace
347 \pgfplots@createcolormap@grabnext@read@pos@
348 }%
349 \def\pgfplots@createcolormap@grabnext@read@pos@#1){%
350 \def\pgfplots@loc@TMPb{#1}% position
351 \def\b@pgfplots@createcolormap@pos@mode{m}% [m]anual
352 \pgfutil@ifnextchar\pgfplots@EOI{%
353 % OK
354 \pgfplots@gobble@until@EOI
355 }{%
356 \pgfplots@createcolormap@error#1)%
357 }%
358 }%
359
360 %%%%%%%%%%
361
362 % Splits '<argument> of <source name>*' into (\pgfplotsretval,
363 % \pgfplotsretvalb).
364 %
365 % The 'of' part is optional. If it is missing, '\pgfplotsretval'
366 % contains the entire argument and '\pgfplotsretvalb' is the current
367 % colormap.
368 %
369 % Note that '<source name>*' is typically just a colormap name (i.e. without
370 % '*'), but it _may_ contain key-value lists! They will be returned as-is.
371 % #1: the string to split
372 % #2: '1' if '#1' may contain ',' and '0' otherwise
373 \def\pgfplots@createcolormap@special@split#1#2{%
374 \pgfutil@in@{of }{#1}%
375 \ifpgfutil@in@
376 \pgfplots@createcolormap@special@split@#1\pgfplots@EOI
377 \else
378 \if1#2\relax
379 % do not check it -- commas are allowed here!
380 \pgfutil@in@false
381 \else
382 \pgfutil@in@{,}{#1}%
383 \fi
384 \ifpgfutil@in@
385 % ah - might be something like '5, target pos={1,2,3}'.
386 % -> define \pgfplotsretval='5' and
387 % \pgfplotsretvalb='<colormap name>, target pos={1,2,3}':
388 %
389 \pgfplots@createcolormap@special@split@command#1\pgfplots@EOI
390 \t@pgfplots@tokb=\expandafter{\pgfplotsretvalb}%
391 \pgfkeysgetvalue{/pgfplots/colormap name}\pgfplotsretvalb
392 \edef\pgfplotsretvalb{\pgfplotsretvalb,\the\t@pgfplots@tokb}%
393 \else
394 \pgfkeys@spdef\pgfplotsretval{#1}%
395 \pgfkeysgetvalue{/pgfplots/colormap name}\pgfplotsretvalb
396 \fi
397 \fi
398 %\message{Split (#1) --> '\pgfplotsretval', '\pgfplotsretvalb'^^J}%
399 }%
400 \def\pgfplots@createcolormap@special@split@#1of #2\pgfplots@EOI{%
401 \pgfkeys@spdef\pgfplotsretval{#1}%
402 \pgfkeys@spdef\pgfplotsretvalb{#2}%
403 }
404 \def\pgfplots@createcolormap@special@split@command#1,#2\pgfplots@EOI{%
405 \pgfkeys@spdef\pgfplotsretval{#1}%
406 \pgfkeys@spdef\pgfplotsretvalb{#2}%
407 }
408
409 % Output: \pgfplotsretval will be populated with the resulting
410 % colormap name.
411 \def\pgfplots@createcolormap@special@ensure@source@cm#1{%
412 \edef\pgfplotsretval{#1}%
413 \pgfplotscolormapifdefined{#1}{}{%
414 % hm... the colormap does not exist? Perhaps someone used
415 % style 'colormap/cool'. Try to define it!
416 \pgfkeysifdefined{/pgfplots/#1/.@cmd}{%
417 \pgfkeysgetvalue{/pgfplots/colormap name}\pgfplots@color@of@colormap@name@old
418 \pgfplotsset{#1}%
419 \pgfkeysgetvalue{/pgfplots/colormap name}\pgfplotsretval
420 \pgfkeyslet{/pgfplots/colormap name}\pgfplots@color@of@colormap@name@old
421 }{%
422 \pgfplots@error{The argument '#1' is no valid colormap.}%
423 }%
424 }%
425 }%
426
427 \newif\ifpgfplots@createcolormap@target@pos@includes@limits@min
428 \newif\ifpgfplots@createcolormap@target@pos@includes@limits@max
429
430 % these keys are only evaluated inside of
431 % \pgfplots@of@colormap@getresult :
432 \pgfqkeys{/pgfplots/of colormap}{%
433 source name/.initial=,
434 target pos/.initial=,
435 target pos min/.initial=,
436 target pos min/insert/.is if=pgfplots@createcolormap@target@pos@includes@limits@min,
437 target pos min*/.style={%
438 /pgfplots/of colormap/target pos min={#1},
439 /pgfplots/of colormap/target pos min/insert=true,
440 },%
441 target pos max/.initial=,
442 target pos max*/.style={%
443 /pgfplots/of colormap/target pos max={#1},
444 /pgfplots/of colormap/target pos max/insert=true,
445 },%
446 target pos max/insert/.is if=pgfplots@createcolormap@target@pos@includes@limits@max,
447 source pos/.initial=,
448 source pos/.set if not empty/.code={%
449 \edef\pgfplots@loc@TMPa{#1}%
450 \ifx\pgfplots@loc@TMPa\pgfutil@empty
451 \else
452 \pgfkeyslet{/pgfplots/of colormap/source pos}\pgfplots@loc@TMPa
453 \fi
454 },
455 %
456 @define/.code={%
457 \pgfplots@error{Please write 'single color' or 'color list' such that pgfplots knows how to interpret values}%
458 \let\pgfplotsretval=\pgfutil@empty
459 },
460 single color/.style={%
461 /pgfplots/of colormap/@define/.code={%
462 \pgfplots@createcolormap@special@process@single
463 },
464 },
465 color list/.style={%
466 /pgfplots/of colormap/@define/.code={%
467 \pgfplots@createcolormap@special@process@list%
468 },
469 },
470 color list,
471 %
472 of colormap/.style={#1},
473 %
474 % 'color of colormap={#1}' is a style which boils down to
475 % '@delegate to@ of colormap={color}{#1}'.
476 % The same is true for
477 % colors of colormap
478 % index of colormap
479 % indices of colormap
480 % samples of colormap
481 %
482 % All use this implementation:
483 % #1: how to interpret results. /pgfplots/of colormap/#1 must be
484 % a valid key (like 'color').
485 % #2: the argument which can be '<source pos> of <source name>' or '<source pos>'.
486 % #3: '1' if the source pos may contain ',' and '0' otherwise
487 @delegate to@ of colormap/.code args={#1#2#3}{%
488 % Convert 'color of colormap={...}' and its variants into
489 % 'of colormap={<list of keys>}':
490 \pgfplots@createcolormap@special@split{#2}{#3}%
491 \edef\pgfplots@loc@TMPa{%
492 #1,%
493 source pos={\pgfplotsretval},%
494 % \pgfplotsretvalb will contain the colormap name
495 % --- but it _can_ also contain further key-value pairs!
496 % Do not add braces here such that further key-value pairs
497 % can be found:
498 source name=\pgfplotsretvalb,%
499 }%
500 \expandafter\pgfkeysalso\expandafter{\pgfplots@loc@TMPa}%
501 },
502 %
503 color/.style={%
504 /pgfplots/of colormap/colormap access=map,
505 /pgfplots/of colormap/single color,
506 /pgfplots/of colormap/source pos/.set if not empty={#1},
507 },
508 const color/.style={%
509 /pgfplots/of colormap/colormap access=piecewise constant,
510 /pgfplots/of colormap/single color,
511 /pgfplots/of colormap/source pos/.set if not empty={#1},
512 },
513 index/.style={%
514 /pgfplots/of colormap/colormap access=direct,
515 /pgfplots/of colormap/single color,
516 /pgfplots/of colormap/source pos/.set if not empty={#1},
517 },
518 colors/.style={%
519 /pgfplots/of colormap/colormap access=map,
520 /pgfplots/of colormap/color list,
521 /pgfplots/of colormap/source pos/.set if not empty={#1},
522 },
523 samples/.style={%
524 /pgfplots/of colormap/colormap access=map,% can be overridden if needed.
525 /pgfplots/of colormap/@define/.code={%
526 \pgfplots@createcolormap@special@process@list@sampled%
527 },
528 /pgfplots/of colormap/source pos/.set if not empty={#1},
529 },%
530 %
531 const colors/.style={%
532 /pgfplots/of colormap/colormap access=piecewise constant,
533 /pgfplots/of colormap/color list,
534 /pgfplots/of colormap/source pos/.set if not empty={#1},
535 },
536 indices/.style={%
537 /pgfplots/of colormap/colormap access=direct,
538 /pgfplots/of colormap/color list,
539 /pgfplots/of colormap/source pos/.set if not empty={#1},
540 },
541 colormap access/.style={/pgfplots/colormap access={#1}},
542 source range/.initial=0:1000,
543 %
544 sample for/.is choice,
545 sample for/default/.code={\def\pgfplots@ofcolorbar@sample@for@choice{m}},
546 sample for/const/.code={\def\pgfplots@ofcolorbar@sample@for@choice{c}},
547 sample for=default,
548 %
549 /pgfplots/of colormap/.unknown/.code={%
550 \pgfplotsutilifstringequal{#1}{\pgfkeysnovalue}{%
551 % This here allows to write 'of colormap={initial}'
552 \pgfplotscolormapifdefined{\pgfkeyscurrentname}{%
553 \edef\pgfplots@loc@TMPa{%
554 \noexpand\pgfkeysalso{%
555 /pgfplots/of colormap/source name={\pgfkeyscurrentname},
556 }%
557 }%
558 \pgfplots@loc@TMPa
559 }{%
560 \pgfplots@error{Unknown key '\pgfkeyscurrentname'. Is this a colormap name? Maybe you need to write \string\pgfplotsset{\pgfkeyscurrentname} first?}%
561 }%
562 }{%
563 \pgfkeysgetvalue{/handlers/.unknown/.@cmd}{\pgfkeys@code}%
564 \expandafter\pgfkeys@code\pgfkeyscurrentvalue\pgfeov%
565 }%
566 },
567 %
568 % allow something like 'of colormap={colormap/PuBuGn}':
569 /pgfplots/of colormap/colormap/.unknown/.code={%
570 \edef\pgfplots@loc@TMPa{\noexpand\pgfplotsset{colormap/\pgfkeyscurrentname}}%
571 \pgfplots@loc@TMPa
572 },%
573 }
574 \pgfplotsinvokeforeach{%
575 color,% defines 'color of colormap'
576 index,% defines 'index of colormap'
577 const color,% defines 'const color of colormap'
578 samples,% defines 'samples of colormap'
579 }{%
580 \def\pgfplots@glob@TMPa{#1}%
581 \ifx\pgfplots@glob@TMPa\pgfutil@empty
582 \else
583 \pgfkeysdef{/pgfplots/of colormap/#1 of colormap}{%
584 \pgfkeysalso{/pgfplots/of colormap/@delegate to@ of colormap={#1}{##1}{0}}%
585 }%
586 \fi
587 }%
588 \pgfplotsinvokeforeach{%
589 indices,% defines 'indices of colormap'
590 colors,% defines 'colors of colormap'
591 const colors,% defines 'const colors of colormap'
592 }{%
593 \def\pgfplots@glob@TMPa{#1}%
594 \ifx\pgfplots@glob@TMPa\pgfutil@empty
595 \else
596 \pgfkeysdef{/pgfplots/of colormap/#1 of colormap}{%
597 \pgfkeysalso{/pgfplots/of colormap/@delegate to@ of colormap={#1}{##1}{1}}%
598 }%
599 \fi
600 }%
601
602 % This is the main implementation of 'of colormap'. It is shared by
603 % both cycle lists and colormaps.
604 %
605 \def\pgfplots@of@colormap@getresult#1{%
606 \pgfkeysinterruptkeyfilter
607 \pgfqkeys{/pgfplots/of colormap}{%
608 % ensure that this here is not inherited from the axis'
609 % configuration -- reset it:
610 colormap access=map,%
611 #1}%
612 \pgfkeysgetvalue{/pgfplots/of colormap/source name}\pgfplots@loc@TMPa
613 \edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa}%
614 \ifx\pgfplots@loc@TMPa\pgfutil@empty
615 \else
616 \pgfkeyslet{/pgfplots/colormap name}\pgfplots@loc@TMPa
617 \fi
618 \pgfplots@createcolormap@special@ensure@source@cm{\pgfkeysvalueof{/pgfplots/colormap name}}%
619 \pgfkeyslet{/pgfplots/colormap name}\pgfplotsretval
620 %
621 \pgfqkeys{/pgfplots/of colormap}{@define}%
622 \endpgfkeysinterruptkeyfilter
623 }%
624
625
626 \def\pgfplots@createcolormap@special@process@single@error{%
627 \pgfplots@error{Did not find a suitable input source pos in a 'of colormap' specification. Did you forget the 'source pos'? It can be given as 'colors of colormap=(source pos of name)' or 'of colormap=(source pos=...,..)'}%
628 \pgfkeyssetvalue{/pgfplots/of colormap/source pos}{0}%
629 }%
630 \def\pgfplots@createcolormap@special@process@single@error@comma{%
631 \pgfplots@error{Found an unexpected comma in 'source pos=\pgfkeysvalueof{/pgfplots/of colormap/source pos}'. Please use one of the styles 'colors', 'indices', or 'const colors' in order to process more than one position}%
632 \pgfkeyssetvalue{/pgfplots/of colormap/source pos}{0}%
633 }%
634 \def\pgfplots@createcolormap@special@process@single{%
635 \begingroup
636 \let\pgfplots@color@of@colormap@access=\pgfplots@colormap@access
637 \pgfkeysgetvalue{/pgfplots/of colormap/source range}\pgfplotspointmetatransformedrange
638 \ifx\pgfplotspointmetatransformedrange\pgfutil@empty
639 % evaluated by \pgfplots@color@of@colormap@define...
640 \let\pgfplotspointmetatransformedrange=\pgfplotscolormaprange
641 \fi
642 %
643 \pgfkeysgetvalue{/pgfplots/of colormap/source pos}\pgfplots@loc@TMPa
644 \edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa}%
645 \ifx\pgfplots@loc@TMPa\pgfutil@empty
646 \pgfplots@createcolormap@special@process@single@error
647 \else
648 \edef\pgfplots@loc@TMPa{%
649 \noexpand\pgfutil@in@{,}{\pgfplots@loc@TMPa}%
650 }%
651 \pgfplots@loc@TMPa
652 \ifpgfutil@in@
653 \pgfplots@createcolormap@special@process@single@error@comma
654 \else
655 \pgfmathparse{\pgfkeysvalueof{/pgfplots/of colormap/source pos}}%
656 \pgfkeyslet{/pgfplots/of colormap/source pos}\pgfmathresult
657 \fi
658 \fi
659 %
660 \pgflibraryfpuifactive{\pgfkeys{/pgf/fpu=false}}{}%
661 %
662 \edef\pgfplots@loc@TMPa{%
663 \noexpand\pgfplots@color@of@colormap@define{\pgfkeysvalueof{/pgfplots/of colormap/source pos}}%
664 }%
665 \pgfplots@loc@TMPa
666 %
667 \pgfplots@createcolormap@special@process@single@define
668 \pgfmath@smuggleone\pgfplotsretval
669 \endgroup
670 }%
671
672 \def\pgfplots@createcolormap@special@process@single@define{%
673 \pgfkeysgetvalue{/pgfplots/of colormap/target pos}\pgfplots@temp@pos
674 \ifx\pgfplots@temp@pos\pgfutil@empty
675 \else
676 \edef\pgfplots@temp@pos{(\pgfplots@temp@pos)}%
677 \fi
678 %
679 \edef\pgfplotsretval{%
680 \csname pgfpl@cm@\pgfkeysvalueof{/pgfplots/colormap name}@colspace\endcsname\pgfplots@temp@pos=(\pgfmathresult)%
681 }%
682 }%
683 \let\pgfplots@createcolormap@special@process@single@define@CM=\pgfplots@createcolormap@special@process@single@define%
684
685 \def\pgfplots@createcolormap@special@process@list@sanitize@selection{%
686 \pgfkeysgetvalue{/pgfplots/of colormap/source pos}\pgfplots@loc@TMPa
687 \edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa}%
688 \ifx\pgfplots@loc@TMPa\pgfutil@empty
689 % default to a suitable source pos.
690 \ifnum\pgfplots@pos@size<2
691 % We have either 0 positions or 1 position.
692 % This is clearly insufficient and we assume that this
693 % position argument merely gives the start point for the
694 % list.
695 %
696 % Select all of the input colormap:
697 \edef\pgfplots@loc@TMPa{%
698 \noexpand\pgfkeysalso{%
699 /pgfplots/of colormap/source pos={0,...,\pgfplotscolormaplastindexof{\pgfkeysvalueof{/pgfplots/colormap name}}},%
700 /pgfplots/of colormap/indices,
701 }%
702 }%
703 \pgfplots@loc@TMPa
704 \else
705 % hm... we have no source pos, but we have positions! In
706 % this case, we _sample_ source pos uniformly with one
707 % sample for each position!
708 \pgfkeyslet{/pgfplots/of colormap/source pos}\pgfplots@pos@size
709 \pgfplots@createcolormap@special@process@list@sampled@define{P}%
710 \fi
711 \fi
712 }
713 \def\pgfplots@createcolormap@special@process@list@limits{%
714 \begingroup
715 %
716 \pgfkeysgetvalue{/pgfplots/of colormap/target pos}\pgfplots@target
717 \ifx\pgfplots@target\pgfutil@empty
718 \else
719 \pgfkeys{/pgf/fpu=true}%
720 \pgfkeysgetvalue{/pgfplots/of colormap/target pos min}\pgfplots@target@min
721 \pgfkeysgetvalue{/pgfplots/of colormap/target pos max}\pgfplots@target@max
722 \pgfplots@loc@tmpfalse
723 \ifx\pgfplots@target@min\pgfutil@empty
724 \else
725 \pgfmathparse\pgfplots@target@min
726 \let\pgfplots@target@min=\pgfmathresult
727 \pgfplots@loc@tmptrue
728 \fi
729 \ifx\pgfplots@target@max\pgfutil@empty
730 \else
731 \pgfmathparse\pgfplots@target@max
732 \let\pgfplots@target@max=\pgfmathresult
733 \pgfplots@loc@tmptrue
734 \fi
735 \ifpgfplots@loc@tmp
736 % Ah - we _have_ limit constraints! Enforce them:
737 \def\b@pgfplots@isfirst{1}%
738 \pgfmathfloatcreate{1}{1.0}{324}%
739 \let\pgfplots@firstpos\pgfmathresult%
740 \let\pgfplots@lastpos\pgfmathresult%
741 \pgfplotsapplistXnewempty\pgfplots@createcolormap@trg@accum
742 \def\pgfplots@loc@TMPa{\pgfplotsforeachungrouped \x in}%
743 \expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@target}{%
744 \ifx\x\pgfutil@empty
745 \else
746 \pgfmathparse{\x}%
747 \let\x=\pgfmathresult
748 \ifx\pgfplots@target@min\pgfutil@empty
749 \else
750 \pgfmathfloatlessthan{\x}{\pgfplots@target@min}%
751 \ifpgfmathfloatcomparison
752 \let\x=\pgfutil@empty
753 \fi
754 \fi
755 \ifx\pgfplots@target@max\pgfutil@empty
756 \else
757 \ifx\x\pgfutil@empty
758 \else
759 \pgfmathfloatlessthan{\pgfplots@target@max}{\x}%
760 \ifpgfmathfloatcomparison
761 \let\x=\pgfutil@empty
762 \fi
763 \fi
764 \fi
765 %
766 \ifx\x\pgfutil@empty
767 \else
768 \let\pgfplots@lastpos=\x
769 \if1\b@pgfplots@isfirst
770 \let\pgfplots@firstpos=\x
771 \def\b@pgfplots@isfirst{0}%
772 \else
773 \edef\x{,\x}%
774 \fi
775 \expandafter\pgfplotsapplistXpushback\expandafter{\x}\to\pgfplots@createcolormap@trg@accum
776 \fi
777 \fi
778 }%
779 %
780 \ifpgfplots@createcolormap@target@pos@includes@limits@max
781 \ifx\pgfplots@target@max\pgfutil@empty
782 \else
783 \pgfmathfloatifapproxequalrel{\pgfplots@lastpos}{\pgfplots@target@max}{%
784 }{%
785 \let\x=\pgfplots@target@max
786 \if1\b@pgfplots@isfirst
787 \def\b@pgfplots@isfirst{0}%
788 \else
789 \edef\x{,\x}%
790 \fi
791 \expandafter\pgfplotsapplistXpushback\expandafter{\x}\to\pgfplots@createcolormap@trg@accum
792 }%
793 \fi
794 \fi
795 %
796 \pgfplotsapplistXlet\pgfplots@target=\pgfplots@createcolormap@trg@accum
797 %
798 \ifpgfplots@createcolormap@target@pos@includes@limits@min
799 \ifx\pgfplots@target@min\pgfutil@empty
800 \else
801 \pgfmathfloatifapproxequalrel{\pgfplots@firstpos}{\pgfplots@target@min}{%
802 }{%
803 \let\x=\pgfplots@target@min
804 \if1\b@pgfplots@isfirst
805 \let\pgfplots@target=\x
806 \else
807 \edef\pgfplots@target{\x,\pgfplots@target}%
808 \fi
809 }%
810 \fi
811 \fi
812 \fi
813 \fi
814 %
815 \global\let\pgfplots@glob@TMPb=\pgfplots@target
816 \endgroup
817 %\message{limit application: \pgfkeysvalueof{/pgfplots/of colormap/target pos} ^^J -->\pgfplots@glob@TMPb^^J}%
818 \pgfkeyslet{/pgfplots/of colormap/target pos}\pgfplots@glob@TMPb
819 }%
820
821 \def\pgfplots@createcolormap@special@process@list@define@target@array{%
822 \pgfplots@createcolormap@special@process@list@limits%
823 %
824 \pgfkeysgetvalue{/pgfplots/of colormap/target pos}\pgfplots@loc@TMP
825 \expandafter\pgfplotsarraynew\expandafter\pgfplots@pos@array\expandafter{\pgfplots@loc@TMP}%
826 %
827 \pgfplotsarraysizetomacro\pgfplots@pos@array\to\pgfplots@pos@size
828 }%
829
830 % PRECONDITION: Must be invoked within \pgfplots@of@colormap@getresult
831 \def\pgfplots@createcolormap@special@process@list{%
832 \begingroup
833 \pgfkeys{/pgf/fpu=true}%
834 \pgfplots@createcolormap@special@process@list@define@target@array
835 %
836 \pgfplotsapplistXnewempty\pgfplots@createcolormap@special@process@result
837 %
838 \gdef\c@pgfplots@elem{0}%
839 %
840 \def\pgfplots@createcolormap@special@process@list@append{%
841 \pgfplots@createcolormap@special@process@single
842 %
843 % append separator
844 \t@pgfplots@toka=\expandafter{\pgfplotsretval}%
845 \t@pgfplots@tokb=\expandafter{\pgfplots@createcolormap@special@process@list@separator}%
846 \edef\pgfplotsretval{\the\t@pgfplots@toka\the\t@pgfplots@tokb}%
847 %
848 \expandafter\pgfplotsapplistXpushback\pgfplotsretval\to\pgfplots@createcolormap@special@process@result
849 }%
850 %
851 \pgfplots@createcolormap@special@process@list@sanitize@selection
852 %
853 \pgfkeysgetvalue{/pgfplots/of colormap/source pos}\pgfplots@source
854 %
855 \def\pgfplots@loc@TMPa{\pgfplotsforeachungrouped \x in }%
856 \expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@source}{%
857 %
858 \pgfkeyslet{/pgfplots/of colormap/source pos}\x
859 %
860 \ifnum\c@pgfplots@elem<\pgfplots@pos@size\relax
861 \pgfplotsarrayselect\c@pgfplots@elem\of\pgfplots@pos@array\to\pgfplots@loc@TMPa
862 \pgfkeyslet{/pgfplots/of colormap/target pos}\pgfplots@loc@TMPa
863 \else
864 % auto-position:
865 \pgfkeyslet{/pgfplots/of colormap/target pos}\pgfutil@empty
866 \fi
867 %
868 \pgfplots@createcolormap@special@process@list@append
869 %
870 \pgfplotsutil@advancestringcounter@global\c@pgfplots@elem
871 }%
872 %
873 \pgfutil@loop
874 \ifnum\c@pgfplots@elem<\pgfplots@pos@size\relax
875 \pgfplotsarrayselect\c@pgfplots@elem\of\pgfplots@pos@array\to\pgfplots@loc@TMPa
876 \pgfkeysgetvalue{/pgfplots/of colormap/source pos}\x
877 \pgfplotswarning{too many colormap positions}{index \c@pgfplots@elem\space (value \pgfplots@loc@TMPa)}\pgfeov%
878 \pgfplotsutil@advancestringcounter@global\c@pgfplots@elem
879 %
880 \pgfutil@repeat
881 %
882 \pgfplotsapplistXlet\pgfplotsretval=\pgfplots@createcolormap@special@process@result
883 \global\let\pgfplots@glob@TMPa=\pgfplotsretval
884 \endgroup
885 \let\pgfplotsretval=\pgfplots@glob@TMPa
886 %\message{of colormap with list functionality results in \meaning\pgfplotsretval^^J}%
887 }%
888 \def\pgfplots@createcolormap@special@process@list@sampled{%
889 \begingroup
890 \pgfkeys{/pgf/fpu=true}%
891 \pgfplots@createcolormap@special@process@list@define@target@array
892 %
893 % no need to reapply it in \pgfplots@createcolormap@special@process@list:
894 \let\pgfplots@createcolormap@special@process@list@define@target@array=\relax
895 %
896 \pgfplots@createcolormap@special@process@list@sampled@define{S}%
897 \pgfplots@createcolormap@special@process@list
898 \global\let\pgfplots@glob@TMPa=\pgfplotsretval
899 \endgroup
900 \let\pgfplotsretval=\pgfplots@glob@TMPa
901 }
902
903 % Defines
904 % * 'source range',
905 % * 'source pos',
906 % in a way such that it implements 'samples of colormap'
907 % #1: 'S' if it _must_ satisfy the number of samples and 'P' if it
908 % _must_ satisfy the positions
909 \def\pgfplots@createcolormap@special@process@list@sampled@define#1{%
910 \begingroup
911 \pgfkeysgetvalue{/pgfplots/of colormap/source pos}\pgfplots@source
912 %
913 \def\b@pgfplots@special@interval{0}%
914 \def\b@pgfplots@special@interval@additional{0}%
915 \if c\pgfplots@ofcolorbar@sample@for@choice%
916 % or colormap/sample for=const:
917 % sample one less and replicate the last color. This
918 % is to compensate for 'colormap access/extra interval width=0'
919 % (which is the default for colormaps with positions)
920 \ifnum\pgfplots@pos@size>1
921 % ah - we have at least 2 positions and 'extra interval width=0' applies!
922 \if S#1%
923 \c@pgf@counta=\pgfplots@source\relax
924 \advance\c@pgf@counta by1 %
925 \ifnum\pgfplots@pos@size=\c@pgf@counta
926 \else
927 \pgfplotsthrow{too few colormap positions}{\pgfplots@pos@size}{There is an unexpected number of arguments to 'target pos' for 'samples of colormap=(\pgfplots@source)'. Please provide \the\c@pgf@counta\space positions, not \pgfplots@pos@size}\pgfeov%
928 \fi
929 \fi
930 \if S#1%
931 % this is the case
932 % samples of colormap={5, target pos={<6 positions>}}
933 % -> we need to replicate the last color such that we see the rightmost color of the input map
934 \def\b@pgfplots@special@interval{1}%
935 % -> we also need one more sample point (one for each position):
936 \def\b@pgfplots@special@interval@additional{1}%
937 \else
938 % we have pgfplots@pos@size=pgfplots@source.
939 \if1\b@pgfplots@createcolormap@found@more@colors
940 % there are more positions/colors!? Ok, no need to
941 % apply it here:
942 \def\b@pgfplots@special@interval{0}%
943 \else
944 \def\b@pgfplots@special@interval{1}%
945 \fi
946 \fi
947 \else
948 \def\b@pgfplots@special@interval{0}%
949 \fi
950 \else
951 \def\b@pgfplots@special@interval{0}%
952 \ifnum\pgfplots@pos@size>1
953 % ah - we have at least 2 positions
954 \if S#1%
955 \ifnum\pgfplots@pos@size=\pgfplots@source
956 \else
957 \pgfplotsthrow{too few colormap positions}{\pgfplots@pos@size}{There is an unexpected number of arguments to 'target pos' for 'samples of colormap=(\pgfplots@source)'. Please provide \pgfplots@source\space positions, not \pgfplots@pos@size}\pgfeov%
958 \fi
959 \fi
960 \fi
961 \fi
962 %
963 \if1\b@pgfplots@special@interval@additional
964 \c@pgf@counta=\pgfplots@source\relax
965 \advance\c@pgf@counta by+1
966 \edef\pgfplots@source{\the\c@pgf@counta}%
967 \fi
968 \if1\b@pgfplots@special@interval
969 \begingroup
970 \c@pgf@counta=\pgfplots@source\relax
971 \advance\c@pgf@counta by-1
972 %
973 \pgfplotsapplistXnewempty\pgfplots@createcolormap@trg@accum
974 \ifnum\c@pgf@counta<2
975 \pgfmathfloatcreate{0}{0.0}{0}%
976 \expandafter\pgfplotsapplistXpushback\expandafter{\pgfmathresult,}\to\pgfplots@createcolormap@trg@accum
977 \else
978 \edef\pgfplots@source{\the\c@pgf@counta}%
979 \pgfplots@domain@to@foreach 0:1000\relax{\pgfplots@source}%
980 %
981 \def\pgfplots@loc@TMPa{\pgfplotsforeachungrouped \x in}%
982 \expandafter\pgfplots@loc@TMPa\expandafter{\pgfplotsretval}{%
983 \expandafter\pgfplotsapplistXpushback\expandafter{\x,}\to\pgfplots@createcolormap@trg@accum
984 }%
985 \fi
986 %
987 \pgfmathfloatcreate{1}{1.0}{3}%
988 \expandafter\pgfplotsapplistXpushback\expandafter{\pgfmathresult}\to\pgfplots@createcolormap@trg@accum
989 %
990 \pgfplotsapplistXlet\pgfplots@target=\pgfplots@createcolormap@trg@accum
991 \global\let\pgfplots@glob@TMPa=\pgfplots@target
992 \endgroup
993 %
994 \let\pgfplotsretval=\pgfplots@glob@TMPa
995 \else
996 \pgfplots@domain@to@foreach 0:1000\relax{\pgfplots@source}%
997 \fi
998 \pgfmath@smuggleone\pgfplotsretval
999 \endgroup
1000 \pgfkeyslet{/pgfplots/of colormap/source pos}\pgfplotsretval
1001 \pgfqkeys{/pgfplots/of colormap}{%
1002 source range=0:1000,%
1003 }%
1004 %\message{define sample positions(#1) = \pgfplotsretval^^J}%
1005 }%
1006
1007
1008 \def\pgfplots@createcolormap@special@process@list@separator@CM{ }%
1009 \let\pgfplots@createcolormap@special@process@list@separator=\pgfplots@createcolormap@special@process@list@separator@CM
1010 %%%%%%%%%%
1011
1012 \def\b@pgfplots@createcolormap@found@more@colors{0}%
1013
1014 \def\pgfplots@createcolormap@grabnext@complete{%
1015 \edef\pgfplots@loc@TMPd{%
1016 \noexpand\pgfutil@in@{of color}{\pgfplots@loc@TMPa}%
1017 }%
1018 \pgfplots@loc@TMPd
1019 \ifpgfutil@in@
1020 \def\pgfplots@loc@TMPd{%
1021 \pgfplots@createcolormap@ifhasmorecolors{%
1022 \def\b@pgfplots@createcolormap@found@more@colors{1}%
1023 \pgfplots@createcolormap@grabnext@complete@of@colormap
1024 }{%
1025 \def\b@pgfplots@createcolormap@found@more@colors{0}%
1026 \pgfplots@createcolormap@grabnext@complete@of@colormap
1027 }%
1028 }%
1029 \else
1030 % ok, this is a 'normal' color specification with position,
1031 % colorspace, and color data.
1032 %
1033 \edef\pgfplots@loc@TMPa{%
1034 {\pgfplots@loc@TMPb}% position
1035 {%
1036 \pgfplots@loc@TMPa% colorspace
1037 =\pgfplots@loc@TMPc% color data
1038 }%
1039 }%
1040 \expandafter\pgfplots@createcolormap@nextcolor\pgfplots@loc@TMPa
1041 %
1042 % continue loop:
1043 \def\pgfplots@loc@TMPd{\pgfplots@createcolormap@}%
1044 \fi
1045 %
1046 %
1047 % continue loop:
1048 \pgfplots@loc@TMPd
1049 }%
1050
1051 \def\pgfplots@createcolormap@grabnext@complete@of@colormap{%
1052 % ah - a special one based on another colormap!
1053 % convert it into the standard format:
1054 \begingroup
1055 \let\pgfplotscolormap@at=\pgfplots@loc@TMPb
1056 \let\pgfplotscolormap@argument=\pgfplots@loc@TMPc
1057 \let\pgfplotscolormap@key=\pgfplots@loc@TMPa
1058 %
1059 \pgfplots@createcolormap@grabnext@complete@ofcolormap
1060 \pgfmath@smuggleone\pgfplotsretval
1061 \endgroup
1062 %
1063 \expandafter\pgfplots@createcolormap@\pgfplotsretval
1064 }%
1065
1066 % INPUT:
1067 % \pgfplotscolormap@at
1068 % \pgfplotscolormap@argument
1069 % \pgfplotscolormap@key
1070 % OUTPUT:
1071 % The result of /pgfplots/of colormap/@define.
1072 % For the normal colormap definition, it populates
1073 % \pgfplotsretval with the color specifications as they should
1074 % be processed by the colormap definition code.
1075 \def\pgfplots@createcolormap@grabnext@complete@ofcolormap{%
1076 \t@pgfplots@tokb=\expandafter{\pgfplotscolormap@argument}%
1077 \edef\pgfplotscolormap@keyvalue{%
1078 \if m\b@pgfplots@createcolormap@pos@mode
1079 % ah - we have had manually provided positions before.
1080 % Well, keep them. Otherwise, we will stay at the default
1081 % placement.
1082 target pos={\pgfplotscolormap@at},%
1083 \fi
1084 % ... but can be overridden here:
1085 \pgfplotscolormap@key={\the\t@pgfplots@tokb},%
1086 }%
1087 %
1088 \let\pgfplots@createcolormap@special@process@single@define=\pgfplots@createcolormap@special@process@single@define@CM
1089 \let\pgfplots@createcolormap@special@process@list@separator=\pgfplots@createcolormap@special@process@list@separator@CM
1090 %
1091 % finally, process the keys:
1092 \expandafter\pgfplots@of@colormap@getresult\expandafter{%
1093 \pgfplotscolormap@keyvalue,
1094 }%
1095 %\message{\pgfplotscolormap@key={\pgfplotscolormap@argument} -> '\pgfplotscolormap@keyvalue' -> \pgfplotsretval^^J}%
1096 }%
1097
1098 \def\pgfplots@createcolormap@grabnext@computenextposition{%
1099 % determine next step size automatically:
1100 \expandafter\pgfplotsarraycheckempty\expandafter{\pgfplots@createcolormap@name}%
1101 \ifpgfplotsarrayempty
1102 % first: just use 0.
1103 \pgfmathfloatcreate{0}{0.0}{0}%
1104 \else
1105 % not first:
1106 \ifx\pgfplots@createcolormap@H\pgfutil@empty
1107 % ah; we really have to deduce something. We are at the
1108 % second node:
1109 %\def\pgfmathresult{1cm}%
1110 \pgfmathfloatcreate{1}{2.845274}{1}% 1cm=28.45274pt . Backw compat
1111 \else
1112 \pgfmathfloatadd@\pgfplots@createcolormap@LAST\pgfplots@createcolormap@H
1113 \fi
1114 \fi
1115 }%
1116
1117 \def\pgfplots@createcolormap@grabsemicolon;{\pgfplots@createcolormap@}%
1118 \def\pgfplots@createcolormap@grabcomma,{\pgfplots@createcolormap@}%
1119
1120 \def\pgfplots@createcolormap@grabsemicolon@hasnext#1#2;{\pgfplots@createcolormap@ifhasmorecolors{#1}{#2}}%
1121 \def\pgfplots@createcolormap@grabcomma@hasnext#1#2,{\pgfplots@createcolormap@ifhasmorecolors{#1}{#2}}%
1122
1123 {
1124 \catcode`\;=13
1125 \gdef\pgfplots@createcolormap@grabsemicolon@active;{\pgfplots@createcolormap@}%
1126 \gdef\pgfplots@createcolormap@grabsemicolon@active@hasnext#1#2;{\pgfplots@createcolormap@ifhasmorecolors{#1}{#2}}%
1127 }
1128
1129 \def\pgfplots@createcolormap@nextcolor@tostring#1=#2\pgfplots@EOI#3{%
1130 #1(#3)=(#2)%
1131 }%
1132
1133 % #1: h
1134 % #2: a compound element of the form
1135 % '<colorspace>=<comma-separated-color-components>'
1136 % The format is chosen such that it can be forwarded directly to
1137 % \pgfplotscolornormalizesequencenext
1138 %
1139 % see \pgfplotscolornormalizesequencenext for details
1140 \def\pgfplots@createcolormap@nextcolor#1#2{%
1141 \def\pgfplots@createcolormap@context{\pgfplots@createcolormap@nextcolor@tostring#2\pgfplots@EOI{#1}\pgfplots@createcolormap@trace}%
1142 %
1143 \pgfplotscolornormalizesequencenext{#2}%
1144 \let\pgfplots@createcolormap@col@comps=\pgfplotsretvalb
1145 %
1146 \edef\pgfplots@loc@TMPa{{#1}{\pgfplotsretval}}%
1147 \expandafter\pgfplots@createcolormap@nextcolor@\pgfplots@loc@TMPa%
1148 }%
1149 \def\pgfplots@createcolormap@nextcolor@#1#2{%
1150 %\message{processing color #1=(#2)^^J}%
1151 % compute 'h':
1152 \pgfmathparse{#1}%
1153 \let\pgfplots@createcolormap@MAX=\pgfmathresult
1154 %
1155 \ifx\pgfplots@createcolormap@MIN\pgfutil@empty
1156 % it is the first.
1157 \let\pgfplots@createcolormap@MIN=\pgfmathresult
1158 \let\pgfplots@createcolormap@LAST=\pgfmathresult
1159 \fi
1160 %
1161 \expandafter\pgfmathfloatsubtract@\expandafter{\pgfmathresult}{\pgfplots@createcolormap@LAST}%
1162 \let\pgfplots@createcolormap@H@cur=\pgfmathresult
1163 \pgfplots@createcolormap@check@increasing@mesh@width
1164 \let\pgfplots@createcolormap@LAST=\pgfplots@createcolormap@MAX
1165 \ifx\pgfplots@createcolormap@H\pgfutil@empty
1166 \expandafter\pgfplotsarraycheckempty\expandafter{\pgfplots@createcolormap@name}%
1167 \ifpgfplotsarrayempty
1168 \else
1169 \let\pgfplots@createcolormap@H=\pgfplots@createcolormap@H@cur
1170 \fi
1171 \else
1172 \pgfplots@createcolormap@compute@equalto{\pgfplots@createcolormap@H}{\pgfplots@createcolormap@H@cur}%
1173 \ifpgfmathfloatcomparison
1174 \else
1175 \ifnum\b@pgfplotscreatecolormap@isuniform>1
1176 % force reinterpolation:
1177 \pgfplotscreatecolormap@reinterpolate{#2}%
1178 \else
1179 % it is NOT uniform!
1180 \def\b@pgfplotscreatecolormap@isuniform{0}%
1181 %
1182 \pgfmathfloatmintwo{\pgfplots@createcolormap@H@cur}{\pgfplots@createcolormap@H}%
1183 \let\pgfplots@createcolormap@H=\pgfmathresult
1184 \fi
1185 \fi
1186 \fi
1187 %\message{found current H@cur = \pgfplots@createcolormap@H@cur\space (\pgfplots@createcolormap@LAST) -> H=\pgfplots@createcolormap@H^^J}%
1188 %
1189 % remember positions:
1190 \expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@createcolormap@MAX,}\to\pgfplots@createcolormap@X
1191 %
1192 \edef\pgfplots@loc@TMPa{\noexpand\pgfplotsarraypushback{#2}\noexpand\to}%
1193 \expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@createcolormap@name}%
1194 \edef\pgfplots@createcolormap@last{#2}%
1195 }%
1196
1197 \def\pgfplots@createcolormap@check@increasing@mesh@width{%
1198 \expandafter\pgfplotsarraycheckempty\expandafter{\pgfplots@createcolormap@name}%
1199 \ifpgfplotsarrayempty
1200 \else
1201 \pgfmathfloatifflags{\pgfplots@createcolormap@H@cur}{1}{%
1202 % ok, H>0
1203 }{%
1204 \pgfmathfloattofixed{\pgfplots@createcolormap@H@cur}%
1205 \pgfplots@error{Colormaps must have increasing positions. The provided colormap has mesh width '\pgfmathresult' at \pgfplots@createcolormap@context. Please assign increasing positions}%
1206 }%
1207 \fi
1208 }%
1209 \def\pgfplots@createcolormap@compute@equalto#1#2{%
1210 %\begingroup
1211 %\pgfmathfloatcreate{1}{1.0}{-4}%
1212 %\let\pgfmathfloat@relthresh=\pgfmathresult
1213 \pgfmathfloatequalto@{#1}{#2}%
1214 %\xdef\pgfplots@glob@TMPa{%
1215 % \noexpand\def\noexpand\pgfmathresult{\pgfmathresult}%
1216 % \ifpgfmathfloatcomparison
1217 % \noexpand\pgfmathfloatcomparisontrue
1218 % \else
1219 % \noexpand\pgfmathfloatcomparisonfalse
1220 % \fi
1221 %}%
1222 %\endgroup
1223 %\pgfplots@glob@TMPa
1224 %\message{equalto (#1,#2) = \pgfmathresult^^J}%
1225 }%
1226 \def\pgfplotscreatecolormap@reinterpolate#1{%
1227 \pgfmathfloatdivide@{\pgfplots@createcolormap@H@cur}{\pgfplots@createcolormap@H}%
1228 % after this group, \pgfmathresult is
1229 % - empty if no reinterpolation is possible,
1230 % - non-empty if reinterpolation IS possible. In this
1231 % case, it contains the integer multiple of H.
1232 \begingroup
1233 \pgfmathfloattofixed{\pgfmathresult}%
1234 \afterassignment\pgfplots@createcolormap@nextRGB@consider@reinterpolation
1235 \c@pgf@counta=\pgfmathresult\relax
1236 \pgfmath@smuggleone\pgfmathresult
1237 \endgroup
1238 \ifx\pgfmathresult\pgfutil@empty
1239 % I can't do that yet.
1240 \else
1241 \let\pgfplots@createcolormap@loop@end=\pgfmathresult
1242 % interpolate missing values using the already fixed H.
1243 % This interpolation procedure is stupid because it works
1244 % only in forward direction - but it works at least.
1245 % For the backwards direction, you can provide the
1246 % meshwidth explicitly at
1247 % \pgfplotscreatecolormap{}{[1pt]}
1248 \pgfplotsforeachungrouped \c@pgfplots@createcolormap in {1,2,...,\pgfplots@createcolormap@loop@end} {%
1249 \pgfmathfloatequalto@{\c@pgfplots@createcolormap}{\pgfplots@createcolormap@loop@end}%
1250 \ifpgfmathfloatcomparison
1251 % omit the last.
1252 \else
1253 \pgfmathparse{\c@pgfplots@createcolormap/\pgfplots@createcolormap@loop@end}%
1254 \let\pgfplots@createcolormap@scale@current=\pgfmathresult
1255 \pgfmathparse{1-\pgfplots@createcolormap@scale@current}%
1256 \let\pgfplots@createcolormap@scale@last=\pgfmathresult
1257 %
1258 \pgfmathfloattofixed\pgfplots@createcolormap@scale@current
1259 \let\pgfplots@createcolormap@scale@current=\pgfmathresult
1260 \pgfmathfloattofixed\pgfplots@createcolormap@scale@last
1261 \let\pgfplots@createcolormap@scale@last=\pgfmathresult
1262 %
1263 \pgfplotscolornormalizesequencezero
1264 \pgfplotscolornormalizesequenceaddweighted
1265 {\pgfplotsretval}%
1266 {\pgfplots@createcolormap@scale@current}%
1267 {#1}%
1268 \pgfplotscolornormalizesequenceaddweighted
1269 {\pgfplotsretval}%
1270 {\pgfplots@createcolormap@scale@last}%
1271 {\pgfplots@createcolormap@last}%
1272 %
1273 %\message{interpolation step \c@pgfplots@createcolormap = \pgfplotsretval^^J}%
1274 \edef\pgfplots@loc@TMPa{%
1275 \noexpand\pgfplotsarraypushback{\pgfplotsretval}%
1276 \noexpand\to}%
1277 \expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@createcolormap@name}%
1278 \fi
1279 }%
1280 \fi
1281 }%
1282 \def\pgfplots@createcolormap@nextRGB@consider@reinterpolation#1\relax{%
1283 \pgf@xa=#1pt
1284 \ifdim\pgf@xa>0.5pt % we have something like 99.995 or so.
1285 % round up and compute 1 - #1:
1286 \advance\c@pgf@counta by1
1287 \pgf@xa=1pt \advance\pgf@xa by-#1pt
1288 \fi
1289 %
1290 % compute relative error:
1291 \pgf@xb=\the\c@pgf@counta pt
1292 \divide\pgf@xb by10000
1293 %\message{Checking H/h = \pgfplots@createcolormap@H@cur pt/\pgfplots@createcolormap@H pt = \the\c@pgf@counta+-\pgf@sys@tonumber\pgf@xa\space: \the\pgf@xa > \the\pgf@xb\space (relative to \the\c@pgf@counta)?}%
1294 %
1295 \ifdim\pgf@xa>\pgf@xb
1296 \begingroup
1297 \if2\b@pgfplotscreatecolormap@isuniform
1298 \pgfplots@error{Non-uniform colormaps are only supported if you write 'compat=1.14' (or higher). Please adopt the compatibility level and retry. The error occurred near '\pgfplots@createcolormap@context'}%
1299 \else
1300 \pgfmathfloattofixed{\pgfplots@createcolormap@H}%
1301 \let\pgfplots@createcolormap@H=\pgfmathresult
1302 \pgfmathfloattofixed{\pgfplots@createcolormap@H@cur}%
1303 \let\pgfplots@createcolormap@H@cur=\pgfmathresult
1304 \pgfplots@error{The provided colormap positions are not multiples of the prescribed mesh width h=\pgfplots@createcolormap@H\space (found one with H/h = \pgfplots@createcolormap@H@cur/\pgfplots@createcolormap@H = \the\c@pgf@counta+-\pgf@sys@tonumber\pgf@xa\space which is no integer). The error occurred near `\pgfplots@createcolormap@context'}%
1305 \fi
1306 \endgroup
1307 \let\pgfmathresult=\pgfutil@empty
1308 \else
1309 \ifnum\c@pgf@counta=0
1310 \let\pgfmathresult=\pgfutil@empty
1311 \else
1312 \edef\pgfmathresult{\the\c@pgf@counta}%
1313 \fi
1314 \fi
1315 }%
1316
1317 \def\pgfplots@colormap@LUA@new#1{%
1318 \ifpgfplots@LUA@supported
1319 \begingroup
1320 \pgfplotscolormapserializecomponentstomacro{#1}\pgfplots@values
1321 \pgfplotscolormapserializeXtomacro{#1}\pgfplots@pos
1322 \pgfplotsutil@directlua{%
1323 local colorspace =^^J%
1324 pgfplots.\csname pgfpl@cm@#1@colspace\endcsname;^^J%
1325 if colorspace then^^J%
1326 pgfplots.ColorMaps["#1"] = pgfplots.ColorMap.new(^^J%
1327 \csname pgfpl@cm@#1@h\endcsname,^^J%
1328 colorspace,^^J%
1329 { \pgfplots@values },^^J
1330 { \pgfplots@pos },^^J
1331 "\csname pgfpl@cm@#1@X@scale@order@z\endcsname"^^J
1332 );^^J%
1333 else^^J%
1334 io.write("There is no LUA colorspace for '\csname pgfpl@cm@#1@colspace\endcsname' - skipping LUA color map definition of #1\string\n");^^J%
1335 end^^J%
1336 }%
1337 \endgroup
1338 \fi
1339 }%
1340
1341 % Executes '#2' if the colormap named '#1' has a uniform grid and '#3'
1342 % if not.
1343 \def\pgfplotscolormapifisuniform#1#2#3{%
1344 \ifnum0=\pgfplotsarraysizeof{pgfpl@cm@#1@X}\relax
1345 #2\relax
1346 \else
1347 #3\relax
1348 \fi
1349 }%
1350
1351 % Shows debug info about colormap #1 into the console.
1352 \def\pgfplots@colormap@showdebuginfofor#1{%
1353 \message{Debug info for color map '#1':^^J}%
1354 \message{(Transformed) Range: [0:\pgfplotscolormaprange]; ^^J}%
1355 \message{H: \csname pgfpl@cm@#1@h\endcsname; ^^J}%
1356 \message{H:^{-1}: \csname pgfpl@cm@#1@invh\endcsname; ^^J}%
1357 \pgfplotsarraysizetomacro{pgfpl@cm@#1}\to\pgfplots@loc@TMPa
1358 \message{Size: \pgfplots@loc@TMPa; ^^J}%
1359 \message{Colorspace: \csname pgfpl@cm@#1@colspace\endcsname^^JValues (\csname pgfpl@cm@#1@col@comps\endcsname\space components each): ^^J}%
1360 \begingroup
1361 \c@pgf@counta=0
1362 \pgfplotscolormapifisuniform{#1}{%
1363 \pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\elem{%
1364 \pgfmath@basic@multiply@{\the\c@pgf@counta}{\csname pgfpl@cm@#1@h\endcsname}%
1365 \message{\#\the\c@pgf@counta=(\pgfmathresult)=(\elem);^^J}%
1366 \advance\c@pgf@counta by1 %
1367 }%
1368 }{%
1369 \pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\elem{%
1370 \pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#1@X}\to\pgfmathresult
1371 \message{\#\the\c@pgf@counta=(\pgfmathresult)=(\elem);^^J}%
1372 \advance\c@pgf@counta by1 %
1373 }%
1374 }%
1375 \message{^^J}%
1376 \endgroup
1377 }
1378
1379 % #1: comma-separated list of values for the current entry
1380 % #2: color map name
1381 % #3: the current index into the colormap
1382 % #4: the "x coordinate", i.e. the offset within the colormap
1383 %
1384 % Defines \pgfplotsretval
1385 %
1386 % Example:
1387 % \pgfplotscolormaptodatafile[
1388 % output each nth=1,
1389 % output format=csv,
1390 % ]{viridis}
1391 % {viridis.dat}
1392 \def\pgfplotscolormaptodatafile@elem#1#2#3#4{%
1393 \let\pgfplotsretval=\pgfutil@empty
1394 }%
1395
1396 \begingroup
1397 \catcode`\[=1
1398 \catcode`\]=2
1399 \catcode`\{=12
1400 \catcode`\}=12
1401 \xdef\pgfplots@lbrace[{]%
1402 \xdef\pgfplots@rbrace[}]%
1403 \endgroup
1404
1405
1406 \pgfkeys{
1407 /pgfplots/colormap/output each nth/.initial=1,
1408 /pgfplots/colormap/output format/.is choice,
1409 /pgfplots/colormap/output format/csv/.code={%
1410 \def\pgfplotscolormaptodatafile@head##1{%
1411 \let\pgfplotsretval=\pgfutil@empty
1412 }%
1413 \def\pgfplotscolormaptodatafile@elem##1##2##3##4{%
1414 \edef\pgfplotsretval{##4,##1}%
1415 }%
1416 \def\pgfplotscolormaptodatafile@foot##1{%
1417 \let\pgfplotsretval=\pgfutil@empty
1418 }%
1419 },
1420 /pgfplots/colormap/output format/native/.code={%
1421 \def\pgfplotscolormaptodatafile@head##1{%
1422 \edef\pgfplotsretval{\string\pgfplotsset\pgfplots@lbrace colormap={##1}\pgfplots@lbrace}%
1423 }%
1424 \def\pgfplotscolormaptodatafile@elem##1##2##3##4{%
1425 \edef\pgfplotsretval{\csname pgfpl@cm@##2@colspace\endcsname=(##1)}%
1426 }%
1427 \def\pgfplotscolormaptodatafile@foot##1{%
1428 \edef\pgfplotsretval{\pgfplots@rbrace\pgfplots@rbrace}%
1429 }%
1430 },
1431 /pgfplots/colormap/output format=csv,
1432 }
1433
1434
1435 % An export of a color map.
1436 % #1: options. Can use 'output each nth=2' and 'output format=csv|native'
1437 % #2: a color map
1438 % #3: a data file
1439 \def\pgfplotscolormaptodatafile{\pgfutil@ifnextchar[{\pgfplotscolormaptodatafile@}{\pgfplotscolormaptodatafile@[]}}%
1440 \def\pgfplotscolormaptodatafile@[#1]#2#3{%
1441 \begingroup
1442 \pgfqkeys{/pgfplots/colormap}{#1}%
1443 \pgfkeysgetvalue{/pgfplots/colormap/output each nth}{\pgfplots@eachnth}%
1444 \immediate\openout\w@pgf@writea=#3\relax
1445 \pgfplotscolormaptodatafile@head{#2}%
1446 \ifx\pgfplotsretval\pgfutil@empty
1447 \else
1448 \immediate\write\w@pgf@writea{%
1449 \pgfplotsretval
1450 }%
1451 \fi
1452 \gdef\pgfplots@eachnth@cur{0}%
1453 \pgfplotsarrayforeach{pgfpl@cm@#2}\as\elem{%
1454 \ifnum\pgfplots@eachnth@cur=0\relax
1455 \gdef\pgfplots@eachnth@cur{0}%
1456 \pgfplotscolormapifisuniform{#2}{%
1457 \pgfmath@basic@multiply@{\pgfplotsarrayforeachindex}{\csname pgfpl@cm@#2@h\endcsname}%
1458 }{%
1459 \pgfplotsarrayselect\pgfplotsarrayforeachindex\of{pgfpl@cm@#1@X}\to\pgfmathresult
1460 }%
1461 \edef\pgfplots@loc@TMPa{{\elem}{#2}{\pgfplotsarrayforeachindex}{\pgfmathresult}}%
1462 \expandafter\pgfplotscolormaptodatafile@elem\pgfplots@loc@TMPa
1463 \ifx\pgfplotsretval\pgfutil@empty
1464 \else
1465 \immediate\write\w@pgf@writea{%
1466 \pgfplotsretval
1467 }%
1468 \fi
1469 \fi
1470 \pgfplotsutil@advancestringcounter@global\pgfplots@eachnth@cur%
1471 \ifnum\pgfplots@eachnth@cur=\pgfplots@eachnth\relax
1472 \gdef\pgfplots@eachnth@cur{0}%
1473 \fi
1474 }%
1475 \pgfplotscolormaptodatafile@foot{#2}%
1476 \ifx\pgfplotsretval\pgfutil@empty
1477 \else
1478 \immediate\write\w@pgf@writea{%
1479 \pgfplotsretval
1480 }%
1481 \fi
1482 \immediate\closeout\w@pgf@writea
1483 \endgroup
1484 }
1485
1486 % Defines \pgfplotsretval to contain the mesh width of colormap #1.
1487 % If the color map has a non-uniform grid, it returns the SMALLEST
1488 % encountered mesh width.
1489 \def\pgfplotscolormapgetmeshwidth#1{%
1490 \expandafter\let\expandafter\pgfplotsretval\csname pgfpl@cm@#1@h\endcsname%
1491 }%
1492
1493 % defines macro #2 to contain a serialized variant of the color
1494 % components (only the color components!)
1495 \def\pgfplotscolormapserializecomponentstomacro#1#2{%
1496 \pgfplotscolormapserialize@to@macro{pgfpl@cm@#1}{#2}%
1497 }
1498 \def\pgfplotscolormapserialize@to@macro#1#2{%
1499 \pgfplotsapplistXnewempty\pgfplots@serialize@list@
1500 \pgfplots@loc@tmptrue
1501 \expandafter\pgfplotsarrayforeachungrouped\expandafter{#1}\as\elem{%
1502 \ifpgfplots@loc@tmp
1503 \expandafter\pgfplotsapplistXpushback\expandafter{\expandafter{\elem}}\to\pgfplots@serialize@list@
1504 \pgfplots@loc@tmpfalse
1505 \else
1506 \expandafter\pgfplotsapplistXpushback\expandafter,\expandafter{\elem}\to\pgfplots@serialize@list@
1507 \fi
1508 }%
1509 \pgfplotsapplistXlet#2=\pgfplots@serialize@list@
1510 }%
1511
1512 \def\pgfplotscolormapserialize@to@macro@nobraces#1#2{%
1513 \pgfplotsapplistXnewempty\pgfplots@serialize@list@
1514 \pgfplots@loc@tmptrue
1515 \expandafter\pgfplotsarrayforeachungrouped\expandafter{#1}\as\elem{%
1516 \ifpgfplots@loc@tmp
1517 \expandafter\pgfplotsapplistXpushback\elem\to\pgfplots@serialize@list@
1518 \pgfplots@loc@tmpfalse
1519 \else
1520 \expandafter\pgfplotsapplistXpushback\expandafter,\elem\to\pgfplots@serialize@list@
1521 \fi
1522 }%
1523 \pgfplotsapplistXlet#2=\pgfplots@serialize@list@
1524 }%
1525 \def\pgfplotscolormapserializeXtomacro#1#2{%
1526 \pgfplotscolormapserialize@to@macro@nobraces{pgfpl@cm@#1@X}{#2}%
1527 }%
1528
1529 % Copies the contents of the colormap named '#1' into a macro '#2'.
1530 % Invocation of the macro will then re-create the colormap.
1531 %
1532 % #1: color map name
1533 % #2: a macro name
1534 \def\pgfplotscolormapserializetomacro#1#2{%
1535 \begingroup
1536 \pgfplotscolormapserializecomponentstomacro{#1}\pgfplots@serialize@list
1537 \pgfplotscolormapserializeXtomacro{#1}\pgfplots@serialize@list@X
1538 \toks0={\expandafter\def\csname pgfpl@cm@#1@h\endcsname}%
1539 \toks1={\expandafter\def\csname pgfpl@cm@#1@invh\endcsname}%
1540 \toks2={%
1541 \pgfplotsarraynewempty{pgfpl@cm@#1}%
1542 \expandafter\pgfplotsutilforeachcommasep\pgfplots@loc@TMPa\as\pgfplots@loc@TMPb{%
1543 \ifx\pgfplots@loc@TMPb\pgfutil@empty
1544 \else
1545 \expandafter\pgfplotsarraypushback\pgfplots@loc@TMPb\to{pgfpl@cm@#1}%
1546 \fi
1547 }%
1548 }%
1549 \toks3=\expandafter{\pgfplots@serialize@list}%
1550 \toks4=\expandafter{\expandafter\def\csname pgfpl@cm@#1@colspace\endcsname}%
1551 \toks5=\expandafter{\expandafter\def\csname pgfpl@cm@#1@col@comps\endcsname}%
1552 \toks6=\expandafter{\expandafter\def\csname pgfpl@cm@#1@lastindex\endcsname}%
1553 \toks7={%
1554 \pgfplotsarraynewempty{pgfpl@cm@#1@X}%
1555 \expandafter\pgfplotsutilforeachcommasep\pgfplots@loc@TMPa\as\pgfplots@loc@TMPb{%
1556 \ifx\pgfplots@loc@TMPb\pgfutil@empty
1557 \else
1558 \expandafter\pgfplotsarraypushback\pgfplots@loc@TMPb\to{pgfpl@cm@#1@X}%
1559 \fi
1560 }%
1561 }%
1562 \toks8=\expandafter{\pgfplots@serialize@list@X}%
1563 \xdef\pgfplots@glob@TMPa{%
1564 \the\toks0 {\csname pgfpl@cm@#1@h\endcsname}%
1565 \the\toks1 {\csname pgfpl@cm@#1@invh\endcsname}%
1566 \noexpand\def\noexpand\pgfplots@loc@TMPa{\the\toks3 }%
1567 \the\toks2
1568 \the\toks4 {\csname pgfpl@cm@#1@colspace\endcsname}%
1569 \the\toks5 {\csname pgfpl@cm@#1@col@comps\endcsname}%
1570 \the\toks6 {\csname pgfpl@cm@#1@lastindex\endcsname}%
1571 \noexpand\def\noexpand\pgfplots@loc@TMPa{\the\toks8 }%
1572 \the\toks7
1573 \def\expandafter\noexpand\csname pgfpl@cm@#1@X@scale@order@z\endcsname{\csname pgfpl@cm@#1@X@scale@order@z\endcsname}%
1574 }%
1575 \endgroup
1576 \let#2=\pgfplots@glob@TMPa
1577 }%
1578
1579 % Defines \pgfplotsretval to contain an argument for use in \foreachlist
1580 % which results in all the positions.
1581 %
1582 % [#1:#2] : the desired output domain. The smallest position will be
1583 % mapped to #1, the largest to #2, and all in-between will be mapped
1584 % accordingly.
1585 % #3: the colormap name.
1586 %
1587 % Note that this switch depends on the current value of 'colormap
1588 % access': piecewise constant may use different positions.
1589 %
1590 % On output, \pgfplotsretval will contain the result.
1591 \def\pgfplotscolormapgetpositions[#1:#2]#3{%
1592 \begingroup
1593 \if d\pgfplots@colormap@access
1594 \edef\pgfplotsretval{0,1,...,\pgfplotscolormaplastindexof{#3}}%
1595 \else
1596 \if m\pgfplots@colormap@access
1597 \def\b@pgfplots@extra@interval{0}%
1598 \edef\pgfplots@H{\csname pgfpl@cm@#3@h\endcsname}%
1599 \else
1600 \if c\pgfplots@colormap@access
1601 \pgfplotscolormap@piecewiseconst@prepare@scale{#3}%
1602 \edef\pgfplots@H{\pgf@sys@tonumber\pgf@x}%
1603 \fi
1604 \fi
1605 %
1606 \pgfkeys{/pgf/fpu}%
1607 \pgfplotsapplistXnewempty\pgfplots@resultaccum
1608 \pgfplotscolormapifisuniform{#3}{%
1609 \pgfmathparse{#1 + (#2-#1) * \pgfplots@H/1000}%
1610 \let\next=\pgfmathresult
1611 \pgfmathparse{#2}% + (#2-#1)/1000}%
1612 %
1613 \def\b@pgfplots@isfirst{1}%
1614 \edef\pgfplots@loc@TMPa{\noexpand\pgfplotsforeachungrouped\noexpand \x in {#1,\next,...,\pgfmathresult}}%
1615 \pgfplots@loc@TMPa{%
1616 \if0\b@pgfplots@isfirst
1617 \pgfplotsapplistXpushback,\to\pgfplots@resultaccum
1618 \fi
1619 \expandafter\pgfplotsapplistXpushback\expandafter{\x}\to\pgfplots@resultaccum
1620 \def\b@pgfplots@isfirst{0}%
1621 }%
1622 }{%
1623 \pgfmathparse{(#2-#1)/1000}%
1624 \let\pgfplots@scale=\pgfmathresult
1625 \pgfplotsarrayforeachungrouped{pgfpl@cm@#3@X}\as\pgfplots@loc@TMPc{%
1626 \if m\pgfplots@colormap@access
1627 % colormap access=map
1628 \pgfmathparse{#1 + \pgfplots@loc@TMPc * \pgfplots@scale}%
1629 \else
1630 \if1\b@pgfplots@extra@interval
1631 \pgfmathparse{#1 + \pgfplots@loc@TMPc * \pgfplots@H* \pgfplots@scale}%
1632 \else
1633 % DISABLE additional interval!
1634 % Means: use the input position as usual:
1635 \pgfmathparse{#1 + \pgfplots@loc@TMPc * \pgfplots@scale}%
1636 \fi
1637 \fi
1638 \ifnum\pgfplotsarrayforeachindex>0
1639 \pgfplotsapplistXpushback,\to\pgfplots@resultaccum
1640 \fi
1641 \expandafter\pgfmathfloattofixed\expandafter{\pgfmathresult}%
1642 \expandafter\pgfplotsapplistXpushback\expandafter{\pgfmathresult}\to\pgfplots@resultaccum
1643 }%
1644 \if1\b@pgfplots@extra@interval
1645 \pgfmathparse{#2}%
1646 \pgfplotsapplistXpushback,\to\pgfplots@resultaccum
1647 \expandafter\pgfmathfloattofixed\expandafter{\pgfmathresult}%
1648 \expandafter\pgfplotsapplistXpushback\expandafter{\pgfmathresult}\to\pgfplots@resultaccum
1649 \fi
1650 }%
1651 \pgfplotsapplistXlet\pgfplotsretval=\pgfplots@resultaccum
1652 \fi
1653 \pgfmath@smuggleone\pgfplotsretval
1654 \endgroup
1655 }%
1656
1657 % this is a CONSTANT! Do NOT change it!
1658 % Just read it -- just in case \pgfplotscolormaptopdffunction will use
1659 % a different upper bound in the future.
1660 \def\pgfplotscolormappdfmax{1000}%
1661 \def\pgfplotscolormappdfmax@inv{1}%
1662
1663 % Expands to the size of colormap #1 .
1664 \def\pgfplotscolormapsizeof#1{%
1665 \pgfplotscolormapifdefined{#1}{%
1666 \pgfplotsarraysizeof{pgfpl@cm@#1}%
1667 }{%
1668 0%
1669 }%
1670 }%
1671
1672 % Defines \pgfplotsretval to contain the color of color map '#1' at
1673 % index '#2'
1674 \def\pgfplotscolormapgetcolor#1#2{%
1675 \pgfplotsarrayselect{#2}\of{pgfpl@cm@#1}\to\pgfplotsretval
1676 }%
1677
1678 % Expands to the last index of colormap #1 (or -1)
1679 \def\pgfplotscolormaplastindexof#1{%
1680 \pgfplotscolormapifdefined{#1}{%
1681 \csname pgfpl@cm@#1@lastindex\endcsname%
1682 }{%
1683 -1%
1684 }%
1685 }%
1686
1687 % POSTCONDITION:
1688 % 1. for uniform #1:
1689 % \pgf@x contains the MODIFIED mesh width
1690 % \b@pgfplots@extra@interval is 1 if and only if an extra interval
1691 % should be added
1692 % 2. for non-uniform #1:
1693 % \pgf@x is a scaling factor to map input positions to MODIFIED
1694 % positions
1695 % \b@pgfplots@extra@interval is 1 if and only if an extra interval
1696 \def\pgfplotscolormap@piecewiseconst@prepare@scale#1{%
1697 % advance the number of intervals by 1.
1698 \pgfplotscolormapifisuniform{#1}{%
1699 % To this end, we have to compute
1700 % N = n+1
1701 % and
1702 % H = 1000 / (N-1) = 1000/n.
1703 % Store H in \pgf@x:
1704 \expandafter\ifx\csname pgfpl@cm@#1@X@scale@order@z\endcsname\pgfutil@empty%
1705 \c@pgf@countd=\pgfplotscolormapsizeof{#1}\relax
1706 %
1707 \global\pgf@x=1000pt %
1708 \global\divide\pgf@x by\c@pgf@countd
1709 \def\b@pgfplots@extra@interval{1}%
1710 \else
1711 % DISABLE the extra interval!
1712 \global\pgf@x=\csname pgfpl@cm@#1@h\endcsname pt %
1713 \def\b@pgfplots@extra@interval{0}%
1714 \fi
1715 }{%
1716 % the very same idea as for uniform colormaps applies
1717 % for non-uniform maps as well: we create an
1718 % artificial interval at the rightmost end.
1719 % The idea is to think of a temporary map in the range
1720 % [0,1000+ h] where h is the current colormap's
1721 % mesh width.
1722 % Since the domain is [0,1000], we map [0,1000+h]
1723 % linearly into [0,1000].
1724 %
1725 % This here is the scaling factor:
1726 \global\pgf@x=\csname pgfpl@cm@#1@X@scale@order@z\endcsname pt %
1727 % see also
1728 % \pgfplotscolormapfindpiecewiseconst@precomputed for
1729 % comments
1730 \ifdim\pgf@x>0sp %
1731 \def\b@pgfplots@extra@interval{1}%
1732 \else
1733 % disable it
1734 \def\b@pgfplots@extra@interval{0}%
1735 \fi
1736 }%
1737 }%
1738
1739 % #1: colormap name
1740 % #2: yes code
1741 % #3: no code
1742 \def\pgfplotscolormapifrequiresextrainterval#1#2#3{%
1743 \if c\pgfplots@colormap@access
1744 \pgfplotscolormapifisuniform{#1}{%
1745 \expandafter\ifx\csname pgfpl@cm@#1@X@scale@order@z\endcsname\pgfutil@empty%
1746 % no...
1747 #3\relax%
1748 \else
1749 % yes:
1750 #2\relax%
1751 \fi
1752 }{%
1753 \ifdim\csname pgfpl@cm@#1@X@scale@order@z\endcsname pt>0pt
1754 % yes:
1755 #2\relax%
1756 \else
1757 % no:
1758 #3\relax%
1759 \fi
1760 }%
1761 \else
1762 % no:
1763 #3\relax%
1764 \fi
1765 }%
1766 % #1: colormap name
1767 % #2: yes code
1768 % #3: no code
1769 \def\pgfplotscolormapifdrawslastcolor#1#2#3{%
1770 \pgfplotscolormapifrequiresextrainterval{#1}{%
1771 #2\relax%
1772 }{%
1773 \if c\pgfplots@colormap@access
1774 #3\relax%
1775 \else
1776 #2\relax%
1777 \fi
1778 }%
1779 }%
1780
1781 % Writes a PDF function of /FunctionType 3 to \pgfplotsretval
1782 %
1783 % The /Domain argument will be set to [ 0 \pgfplotscolormappdfmax ] and bounds will be
1784 % computed accordingly.
1785 %
1786 % Note that the value depends on 'colormap access'
1787 %
1788 % #1: the colormap
1789 \def\pgfplotscolormaptopdffunction#1{%
1790 \begingroup
1791 \pgfplotscolormapassertexists{#1}%
1792 \pgfplotsapplistXnewempty\pgfplots@resultaccum
1793 \pgfplotsapplistXpushback{
1794 <<
1795 /FunctionType 3
1796 /Domain [0 \pgfplotscolormappdfmax]
1797 /Functions [
1798 }\to\pgfplots@resultaccum%
1799 \c@pgf@counta=0
1800 \c@pgf@countb=\pgfplotsarraysizeof{pgfpl@cm@#1} %
1801 \advance\c@pgf@countb by-1
1802 \def\pgfplots@loc@TMPa{}%
1803 \pgfplotsapplistXnewempty\pgfplots@bounds@accum%
1804 \pgfplotsapplistXnewempty\pgfplots@encode@accum
1805 \ifnum\csname pgfpl@cm@#1@col@comps\endcsname>4
1806 \pgfplots@error{Sorry, processing more than 4 color components (as required for color map #1) is unsupported in this context}%
1807 \fi
1808 %
1809 \def\b@pgfplots@extra@interval{0}%
1810 \if m\pgfplots@colormap@access
1811 % colormap access=map
1812 \def\pgfplots@order{1}%
1813 \global\pgf@x=\csname pgfpl@cm@#1@h\endcsname pt %
1814 \def\pgfplots@C@left{C0}%
1815 \def\pgfplots@C@right{C1}%
1816 \else
1817 \if c\pgfplots@colormap@access
1818 % colormap access=piecewise constant
1819 % This has a dedicated special interval at the rightmost
1820 % end.
1821 % See comments in pgfplotscolormapfindpiecewiseconst@precomputed@
1822 \def\pgfplots@order{0}%
1823 %
1824 \pgfplotscolormap@piecewiseconst@prepare@scale{#1}%
1825 %
1826 % interchange the sequence in the PDF function as it is
1827 % defined as
1828 % y = C0 + x^0 * (C1 - C0) = C1
1829 % -> we want the left interval boundary.
1830 \def\pgfplots@C@left{C1}%
1831 \def\pgfplots@C@right{C0}%
1832 \else
1833 % colormap access=direct
1834 \pgfplots@error{This should never happen}%
1835 % ?
1836 \def\pgfplots@order{0}%
1837 \global\pgf@x=\csname pgfpl@cm@#1@h\endcsname pt %
1838 \def\pgfplots@C@left{C0}%
1839 \def\pgfplots@C@right{C1}%
1840 \fi
1841 \fi
1842 %
1843 \pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\cdata{%
1844 \edef\cdata{%
1845 \expandafter
1846 \expandafter
1847 \csname pgfplotscolormaptopdffunction@convertcdata@\csname pgfpl@cm@#1@col@comps\endcsname\endcsname
1848 \cdata\relax
1849 }%
1850 \ifnum\c@pgf@counta>0
1851 \edef\pgfplots@loc@TMPd{%
1852 <<
1853 /FunctionType 2
1854 /Domain [0 \pgfplotscolormappdfmax]
1855 /\pgfplots@C@left\space [\pgfplots@loc@TMPa] /\pgfplots@C@right\space [\cdata]
1856 /N \pgfplots@order
1857 >>
1858 }%
1859 \expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@loc@TMPd}\to\pgfplots@resultaccum
1860 \ifnum\c@pgf@counta<\c@pgf@countb\relax
1861 \pgfplotscolormapifisuniform{#1}{%
1862 \pgf@xa=\pgf@x
1863 \multiply\pgf@xa by\c@pgf@counta\relax
1864 }{%
1865 \pgfplotsarrayselect{\c@pgf@counta}\of{pgfpl@cm@#1@X}\to\pgfplots@loc@TMPc
1866 \if m\pgfplots@colormap@access
1867 % colormap access=map
1868 \pgf@xa=\pgfplots@loc@TMPc pt %
1869 \else
1870 \if1\b@pgfplots@extra@interval
1871 \pgf@xa=\pgfplots@loc@TMPc\pgf@x%
1872 \else
1873 % DISABLE additional interval!
1874 % Means: use the input position as usual:
1875 \pgf@xa=\pgfplots@loc@TMPc pt %
1876 \fi
1877 \fi
1878 }%
1879 \divide\pgf@xa by\pgfplotscolormappdfmax@inv\relax% we want [ 0 1 ] not [0 1000] as domain XXX : why!?
1880 \edef\pgfplots@loc@TMPc{ \pgf@sys@tonumber\pgf@xa}%
1881 \expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@loc@TMPc}\to\pgfplots@bounds@accum%
1882 \fi
1883 \pgfplotsapplistXpushback{ 0 1}\to\pgfplots@encode@accum%
1884 \fi
1885 \let\pgfplots@loc@TMPa=\cdata
1886 \advance\c@pgf@counta by1
1887 }%
1888 \if1\b@pgfplots@extra@interval
1889 % add an artificial interval.
1890 \edef\pgfplots@loc@TMPd{%
1891 <<
1892 /FunctionType 2
1893 /Domain [0 \pgfplotscolormappdfmax]
1894 /\pgfplots@C@left\space [\cdata] /\pgfplots@C@right\space [\cdata]
1895 /N \pgfplots@order
1896 >>
1897 }%
1898 \expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@loc@TMPd}\to\pgfplots@resultaccum
1899 \advance\c@pgf@counta by-1 %
1900 \pgfplotscolormapifisuniform{#1}{%
1901 \pgf@xa=\pgf@x
1902 \multiply\pgf@xa by\c@pgf@counta\relax
1903 }{%
1904 \pgfplotsarrayselect{\c@pgf@counta}\of{pgfpl@cm@#1@X}\to\pgfplots@loc@TMPc
1905 \pgf@xa=\pgfplots@loc@TMPc\pgf@x%
1906 }%
1907 \divide\pgf@xa by\pgfplotscolormappdfmax@inv\relax% we want [ 0 1 ] not [0 1000] as domain XXX : why!?
1908 \edef\pgfplots@loc@TMPc{ \pgf@sys@tonumber\pgf@xa}%
1909 \expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@loc@TMPc}\to\pgfplots@bounds@accum%
1910 \pgfplotsapplistXpushback{ 0 1}\to\pgfplots@encode@accum%
1911 \fi
1912 \pgfplotsapplistXlet\pgfplotsretval=\pgfplots@resultaccum
1913 \pgfplotsapplistXlet\pgfplotsbounds=\pgfplots@bounds@accum
1914 \pgfplotsapplistXlet\pgfplotsencode=\pgfplots@encode@accum
1915 \t@pgfplots@toka=\expandafter{\pgfplotsretval}%
1916 \t@pgfplots@tokb=\expandafter{\pgfplotsbounds}%
1917 \t@pgfplots@tokc=\expandafter{\pgfplotsencode}%
1918 \xdef\pgfplots@glob@TMPa{%
1919 \the\t@pgfplots@toka
1920 ]
1921 /Bounds [\the\t@pgfplots@tokb]
1922 /Encode [\the\t@pgfplots@tokc]
1923 >>
1924 }%
1925 \endgroup
1926 \let\pgfplotsretval=\pgfplots@glob@TMPa
1927 }%
1928 \expandafter\def\csname pgfplotscolormaptopdffunction@convertcdata@1\endcsname#1\relax{#1}%
1929 \expandafter\def\csname pgfplotscolormaptopdffunction@convertcdata@2\endcsname#1,#2\relax{#1 #2}%
1930 \expandafter\def\csname pgfplotscolormaptopdffunction@convertcdata@3\endcsname#1,#2,#3\relax{#1 #2 #3}%
1931 \expandafter\def\csname pgfplotscolormaptopdffunction@convertcdata@4\endcsname#1,#2,#3,#4\relax{#1 #2 #3 #4}%
1932
1933 % Invokes '#2' if a color map named '#1' exists and '#3' if no such color map exists.
1934 \def\pgfplotscolormapifdefined#1#2#3{\pgfplotsarrayifdefined{pgfpl@cm@#1}{#2}{#3}}%
1935
1936 \def\pgfplotscolormapassertexists#1{%
1937 \pgfplotscolormapifdefined{#1}{}{%
1938 \pgfutil@ifundefined{pgfplotscolormap@errorissued@#1}{%
1939 \pgfplots@error{The colormap `#1' is undefined! Maybe you misspelled it?}%
1940 }{}%
1941 \expandafter\gdef\csname pgfplotscolormap@errorissued@#1\endcsname{1}%
1942 \pgfplotscreatecolormap{#1}{color(0cm)=(blue); color(1cm)=(yellow)}%
1943 }%
1944 }
1945
1946 % Convert a colormap into a PGF shading's color specification for use
1947 % in \pgfdeclare*shading.
1948 %
1949 % #1: the colormap's name.
1950 % #2: the PGF "size" of the shading. It is used to set the right end
1951 % of the color specification.
1952 % #3: a macro which will be filled with the result.
1953 %
1954 % Example:
1955 % \pgfplotscolormaptoshadingspec{my colormap}{4cm}{\output}
1956 % \def\tempb{\pgfdeclarehorizontalshading{myshadingA}{1cm}}
1957 % \expandafter\tempb\expandafter{\temp}
1958 %
1959 % \pgfuseshading{myshadingA}
1960 \def\pgfplotscolormaptoshadingspec#1#2#3{%
1961 \pgfplotscolormapassertexists{#1}%
1962 \begingroup
1963 \def\pgfplots@rgb{rgb}%
1964 \pgfmathparse{#2}%
1965 \expandafter\pgfmathdivide@\expandafter{\pgfmathresult}{\pgfplotscolormaprange}%
1966 \let\pgfplots@loc@TMPb=\pgfmathresult
1967 \pgfmathmultiply@{\csname pgfpl@cm@#1@h\endcsname}{\pgfplots@loc@TMPb}%
1968 \pgf@ya=\pgfmathresult pt
1969 \c@pgf@counta=0
1970 \let#3=\pgfutil@empty
1971 \pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\pgfplotscolormaptoshadingspec@TMP{%
1972 \pgfplotscolormapifisuniform{#1}{%
1973 \pgf@yb=\c@pgf@counta\pgf@ya
1974 }{%
1975 \pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#1@X}\to\pgfplots@loc@TMPd
1976 \pgfmathmultiply@{\pgfplots@loc@TMPd}{\pgfplots@loc@TMPb}%
1977 \pgf@yb=\pgfmathresult pt %
1978 }%
1979 \edef\pgfplots@colspace{\csname pgfpl@cm@#1@colspace\endcsname}%
1980 % FIXME : PGF shadings accept only RGB!
1981 \if1\pgfplotscolormaptoshadingspectorgb
1982 \ifx\pgfplots@colspace\pgfplots@rgb
1983 \else
1984 \pgfutil@ifundefined{pgfpl@cm@#1@warned}{%
1985 \expandafter\gdef\csname pgfpl@cm@#1@warned\endcsname{1}%
1986 \pgfplotswarning{lossy colormap rgb conversion}{#1}{\pgfplots@colspace}\pgfeov%
1987 }{%
1988 }%
1989 \edef\pgf@tempcolor{{\pgfplots@colspace}{\pgfplotscolormaptoshadingspec@TMP}}%
1990 \expandafter\pgfutil@convertcolorspec\pgf@tempcolor{rgb}{\pgfplotscolormaptoshadingspec@TMP}%
1991 \def\pgfplots@colspace{rgb}%
1992 \fi
1993 \fi
1994 \edef\pgfplots@loc@TMPc{\pgfplots@colspace(\the\pgf@yb)=(\pgfplotscolormaptoshadingspec@TMP)}%
1995 \ifx#3\pgfutil@empty
1996 \t@pgfplots@toka={}%
1997 \else
1998 \t@pgfplots@toka=\expandafter{#3; }%
1999 \fi
2000 \t@pgfplots@tokb=\expandafter{\pgfplots@loc@TMPc}%
2001 \edef#3{\the\t@pgfplots@toka \the\t@pgfplots@tokb }%
2002 \advance\c@pgf@counta by1
2003 }%
2004 \pgfmath@smuggleone#3%
2005 \endgroup
2006 }%
2007 \def\pgfplotscolormaptoshadingspectorgb{1}%
2008
2009 % The same as \pgfplotscolormaptoshadingspec, but this here yields the
2010 % *reversed* sequence.
2011 \def\pgfplotscolormapreversedtoshadingspec#1#2#3{%
2012 \begingroup
2013 \let\pgfplotsarrayforeachungrouped=\pgfplotsarrayforeachreversedungrouped
2014 \pgfplotscolormaptoshadingspec{#1}{#2}{#3}%
2015 \pgfmath@smuggleone#3%
2016 \endgroup
2017 }%
2018
2019
2020 % Expands to the transformed range's right end of every colormap. The left
2021 % end is fixed to '0'.
2022 \def\pgfplotscolormaprange{1000}
2023 \pgfmathfloatcreate{1}{1.0}{3}%
2024 \let\pgfplotscolormaprange@float=\pgfmathresult
2025
2026 \def\pgfplotscolormapgetcolorspace#1{%
2027 \edef\pgfplotsretval{\csname pgfpl@cm@#1@colspace\endcsname}%
2028 }%
2029 \def\pgfplotscolormapgetcolorcomps#1{%
2030 \edef\pgfplotsretval{\csname pgfpl@cm@#1@col@comps\endcsname}%
2031 }%
2032 \def\pgfplotscolormapcolorspaceof#1{%
2033 \csname pgfpl@cm@#1@colspace\endcsname%
2034 }%
2035 \def\pgfplotscolormapcolorcompsof#1{%
2036 \csname pgfpl@cm@#1@col@comps\endcsname%
2037 }%
2038
2039
2040 % Linearly maps the number #4 into the colormap #5 and returns the
2041 % interpolated colors into \pgfmathresult. The result will be a triple
2042 % for an RGB colormap and it will contain four numbers for CMYK. The
2043 % components of the result will be in the range [0:1].
2044 %
2045 % [#1:#2] the number range of the data source (i.e. of #4). This is required to
2046 % map into the colormap.
2047 % [#3] (optional) the quantity
2048 % s := \pgfplotscolormaprange / (#2-#1).
2049 % Precomputing this quantity may save a lot of time because
2050 % divisions are expensive in TeX. You can omit [#3] or
2051 % provide an empty string here.
2052 % #4 the number to map.
2053 % #5 the colormap's name. Must be defined with
2054 % \pgfplotscreatecolormap before.
2055 %
2056 % Example:
2057 % \pgfplotscolormapfind[-1:1]{0.2}{my colormap}
2058 \def\pgfplotscolormapfind[#1:#2]{%
2059 \pgfutil@ifnextchar[{%
2060 \pgfplotscolormapfind@precomputed[#1:#2]%
2061 }{%
2062 \pgfplotscolormapfind@precomputed[#1:#2][]%
2063 }%
2064 }%
2065 \def\pgfplotscolormapfind@precomputed[#1:#2][#3]#4#5{%
2066 \ifpgfplots@LUA@supported
2067 \pgfplotscolormapifisuniform{#5}{%
2068 \edef\pgfmathresult{%
2069 \pgfplotsutil@directlua{%
2070 pgfplots.texColorMapPrecomputed("#5", "#1","#2","#4")
2071 }%
2072 }%
2073 \ifx\pgfmathresult\pgfutil@empty
2074 \pgfplotscolormapfind@precomputed@warn@LUA{#5}%
2075 \pgfplotscolormapfind@precomputed@[#1:#2][#3]{#4}{#5}%
2076 \else
2077 %\message{LUA colormapfind[#1:#2](#4)(#5) = \pgfmathresult^^J}%
2078 \fi
2079 }{%
2080 % FIXME : implement LUA for non-uniform colormaps
2081 \pgfplotscolormapfind@precomputed@[#1:#2][#3]{#4}{#5}%
2082 }%
2083 \else
2084 \pgfplotscolormapfind@precomputed@[#1:#2][#3]{#4}{#5}%
2085 \fi
2086 }
2087
2088 \def\pgfplotscolormapfind@precomputed@warn@LUA#1{%
2089 \expandafter\ifx\csname pgfplotscolormapfind@precomputed@warn@LUA@#1\endcsname\relax
2090 \pgfplotswarning{lua colormap unavailable}{#1}\pgfeov%
2091 \expandafter\gdef\csname pgfplotscolormapfind@precomputed@warn@LUA@#1\endcsname{1}%
2092 \fi
2093 }%
2094 \def\pgfplotscolormapfind@transform[#1:#2][#3]#4#5{%
2095 \edef\pgfplots@loc@TMPa{#1:#2}%
2096 \edef\pgfplots@loc@samerange{0:\pgfplotscolormaprange}%
2097 \ifx\pgfplots@loc@TMPa\pgfplots@loc@samerange
2098 % we have phi(#4) = #4 because #4 in [0:1000].
2099 \pgfmathfloatparsenumber{#4}%
2100 \pgfmathfloattofixed\pgfmathresult
2101 \else
2102 % Step 0: compute #3 if it is missing and write it into \pgfplots@loc@TMPa.
2103 %\message{mapping '#4' into colormap '#5' with range [#1:#2] ... ^^J}%
2104 \pgfmathfloatparsenumber{#1}%
2105 \let\pgfplots@L=\pgfmathresult
2106 %
2107 \def\pgfplots@loc@TMPa{#3}%
2108 \ifx\pgfplots@loc@TMPa\pgfutil@empty
2109 \pgfmathfloatparsenumber{#2}%
2110 \let\pgfplots@R=\pgfmathresult
2111 \pgfmathfloatsubtract@{\pgfplots@R}{\pgfplots@L}%
2112 \let\pgfplots@loc@TMPb=\pgfmathresult
2113 \pgfmathfloatdivide@{\pgfplotscolormaprange@float}{\pgfplots@loc@TMPb}%
2114 \else
2115 \pgfmathfloatparsenumber{#3}%
2116 \fi
2117 \let\pgfplots@loc@TMPa=\pgfmathresult
2118 %
2119 % Step 1: perform lookup. Map #4 into the colormap's range
2120 % using the linear trafo
2121 % phi(#4) = ( #4 - #1 ) / (#2-#1) * colormaprange(#5).
2122 % This, determine the INTERVAL number into which #4 falls.
2123 \pgfmathfloatparsenumber{#4}%
2124 \let\pgfplots@V=\pgfmathresult
2125 \pgfmathfloatsubtract@{\pgfplots@V}{\pgfplots@L}%
2126 \expandafter\pgfmathfloatmultiply@\expandafter{\pgfmathresult}{\pgfplots@loc@TMPa}%
2127 \pgfmathfloattofixed\pgfmathresult
2128 \fi
2129 \ifdim\pgfmathresult pt<0pt %
2130 \def\pgfmathresult{0}%
2131 \else
2132 \ifdim\pgfmathresult pt>1000pt %
2133 \def\pgfmathresult{1000}%
2134 \fi
2135 \fi
2136 }%
2137 \def\pgfplotscolormapfind@precomputed@[#1:#2][#3]#4#5{%
2138 \pgfplotscolormapassertexists{#5}%
2139 \begingroup
2140 \pgfplotscolormapfind@transform[#1:#2][#3]{#4}{#5}%
2141 \let\pgfplotscolormapfind@transformedx=\pgfmathresult
2142 %
2143 % Now, we have it in [0,1000]. Find the correct interval:
2144 \pgfplotscolormapifisuniform{#5}{%
2145 \pgfmathmultiply@{\pgfplotscolormapfind@transformedx}{\csname pgfpl@cm@#5@invh\endcsname}%
2146 \let\pgfplotscolormapfind@transformedx@divh=\pgfmathresult
2147 % assign \pgfplotscolormapfind@intervalno := \pgfmathresult
2148 % without '.0' suffix:
2149 \expandafter\pgfplotscolormap@floor@unforgiving\pgfmathresult\relax
2150 % Step 2: interpolate the desired RGB value using vector valued
2151 % interpolation on the identified interval.
2152 \c@pgf@counta=\pgfplotscolormapfind@intervalno\relax
2153 % color^m(x) = ( (x-x_i)/(x_{i+1} - x_i) ) * (c_{i+1}^m - c_i^m ) + c_i^m
2154 % = ( x/h - i ) * ( c_{i+1}^m - c_{i}^m ) + c_i^m
2155 % = s * c_{i+1}^m + S * c_i^m
2156 %
2157 % s= x_h / h -i
2158 \pgfmathsubtract@{\pgfplotscolormapfind@transformedx@divh}{\pgfplotscolormapfind@intervalno}%
2159 \let\pgfplots@loc@factor=\pgfmathresult
2160 }{%
2161 \pgfplotsarraybinarysearch{pgfpl@cm@#5@X}{\pgfplotscolormapfind@transformedx}{0}{\pgfplotscolormapsizeof{#5}}%
2162 \c@pgf@counta=\pgfplotsretval\relax
2163 \ifnum\c@pgf@counta<0
2164 % as per definition of \pgfplotsarraybinarysearch, a
2165 % negative result indicates the "insertion point" ...
2166 \c@pgf@counta=-\c@pgf@counta
2167 % ... plus one.
2168 \advance\c@pgf@counta by-1
2169 %
2170 % But we do not WANT the insertion point! We want the LEFT
2171 % interval boundary!
2172 \advance\c@pgf@counta by-1
2173 \fi
2174 %
2175 % color^m(x) = ( (x-x_i)/(x_{i+1} - x_i) ) * (c_{i+1}^m - c_i^m ) + c_i^m
2176 % = s * c_{i+1}^m + S * c_i^m
2177 %
2178 % s = (x - x_i) / (x_{i+1} - x_i)
2179 \begingroup
2180 \pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5@X}\to\pgfplotscolormapfind@rgb@X@left
2181 \advance\c@pgf@counta by1
2182 \ifnum\c@pgf@counta<\pgfplotsarraysizeof{pgfpl@cm@#5} %
2183 % ok, we really have an interval
2184 \pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5@X}\to\pgfplotscolormapfind@rgb@X@right
2185 %
2186 \pgfmathsubtract@{\pgfplotscolormapfind@rgb@X@right}{\pgfplotscolormapfind@rgb@X@left}%
2187 \let\pgfplotscolormapfind@h=\pgfmathresult
2188 \pgfmathsubtract@{\pgfplotscolormapfind@transformedx}{\pgfplotscolormapfind@rgb@X@left}%
2189 \let\pgfplots@loc@TMPa=\pgfmathresult
2190 \pgfmathdivide@{\pgfplots@loc@TMPa}{\pgfplotscolormapfind@h}%
2191 \let\pgfplots@loc@factor=\pgfmathresult
2192 \else
2193 % irrelevant (not used)
2194 \def\pgfplots@loc@factor{1}%
2195 \fi
2196 \pgfmath@smuggleone\pgfplots@loc@factor
2197 \endgroup
2198 }%
2199 % POSTCONDITION: \c@pgf@counta is the index of the LEFT interval
2200 % and \pgfplots@loc@factor is the factor for the linear interpolation.
2201 %
2202 %\message{mapping [#1,#2] -> [0,\pgfplotscolormaprange] yielded phi(#4) = \pgfplotscolormapfind@transformedx, situated in interval no \the\c@pgf@counta.^^J}%
2203 \pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5}\to\pgfplotscolormapfind@rgb@LEFT
2204 %
2205 % do the stuff which is specific to linear interpolation:
2206 %
2207 % S = 1 - s
2208 \pgfmathsubtract@{1}{\pgfplots@loc@factor}%
2209 \let\pgfplots@loc@factor@two=\pgfmathresult
2210 %
2211 \advance\c@pgf@counta by1 %
2212 \ifnum\c@pgf@counta<\pgfplotsarraysizeof{pgfpl@cm@#5} %
2213 % Ah: (selected index < length) . That means: we have an interval.
2214 \pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5}\to\pgfplotscolormapfind@rgb@RIGHT
2215 %\message{After lookup: the corresponding RGB interval boundaries are [\pgfplotscolormapfind@rgb@LEFT: \pgfplotscolormapfind@rgb@RIGHT].^^J}%
2216 %
2217 %
2218 \pgfplotscolorzero{\csname pgfpl@cm@#5@col@comps\endcsname}%
2219 \pgfplotscoloraddweighted
2220 {\csname pgfpl@cm@#5@col@comps\endcsname}%
2221 {\pgfplotsretval}%
2222 {\pgfplots@loc@factor@two}%
2223 {\pgfplotscolormapfind@rgb@LEFT}%
2224 \pgfplotscoloraddweighted
2225 {\csname pgfpl@cm@#5@col@comps\endcsname}%
2226 {\pgfplotsretval}%
2227 {\pgfplots@loc@factor}%
2228 {\pgfplotscolormapfind@rgb@RIGHT}%
2229 \let\pgfmathresult=\pgfplotsretval
2230 \else
2231 % Ah: selected index = last index. Use the rightmost color!
2232 \let\pgfmathresult=\pgfplotscolormapfind@rgb@LEFT
2233 \fi
2234 \pgfmath@smuggleone\pgfmathresult
2235 \endgroup
2236 %\message{-> got finally mapping(#4, #5) = RGB'\pgfmathresult'.}%
2237 }%
2238
2239
2240 % Maps the number #4 into the colormap #5 using piecewise constant
2241 % interpolation. It returns the interpolated colors into \pgfmathresult. The result will be a triple
2242 % for an RGB colormap and it will contain four numbers for CMYK. The
2243 % components of the result will be in the range [0:1].
2244 %
2245 % [#1:#2] the number range of the data source (i.e. of #4). This is required to
2246 % map into the colormap.
2247 % [#3] (optional) the quantity
2248 % s := \pgfplotscolormaprange / (#2-#1).
2249 % Precomputing this quantity may save a lot of time because
2250 % divisions are expensive in TeX. You can omit [#3] or
2251 % provide an empty string here.
2252 % #4 the number to map.
2253 % #5 the colormap's name. Must be defined with
2254 % \pgfplotscreatecolormap before.
2255 %
2256 % Example:
2257 % \pgfplotscolormapfindpiecewiseconst[-1:1]{0.2}{my colormap}
2258 \def\pgfplotscolormapfindpiecewiseconst[#1:#2]{%
2259 \pgfutil@ifnextchar[{%
2260 \pgfplotscolormapfindpiecewiseconst@precomputed[#1:#2]%
2261 }{%
2262 \pgfplotscolormapfindpiecewiseconst@precomputed[#1:#2][]%
2263 }%
2264 }%
2265 \def\pgfplotscolormapfindpiecewiseconst@precomputed[#1:#2][#3]#4#5{%
2266 \ifpgfplots@LUA@supported
2267 \pgfplotscolormapifisuniform{#5}{%
2268 \edef\pgfmathresult{%
2269 \pgfplotsutil@directlua{%
2270 pgfplots.texColorMapFindPiecewiseConst("#5", #1,#2,#4)
2271 }%
2272 }%
2273 \ifx\pgfmathresult\pgfutil@empty
2274 \pgfplotscolormapfindpiecewiseconst@precomputed@warn@LUA{#5}%
2275 \pgfplotscolormapfindpiecewiseconst@precomputed@[#1:#2][#3]{#4}{#5}%
2276 \else
2277 %\message{LUA colormapfindpiecewiseconst[#1:#2](#4)(#5) = \pgfmathresult^^J}%
2278 \fi
2279 }{%
2280 % FIXME : implement LUA for non-uniform colormaps
2281 \pgfplotscolormapfindpiecewiseconst@precomputed@[#1:#2][#3]{#4}{#5}%
2282 }%
2283 \else
2284 \pgfplotscolormapfindpiecewiseconst@precomputed@[#1:#2][#3]{#4}{#5}%
2285 \fi
2286 }
2287
2288 \def\pgfplotscolormapfindpiecewiseconst@precomputed@warn@LUA#1{%
2289 \expandafter\ifx\csname pgfplotscolormapfindpiecewiseconst@precomputed@warn@LUA@#1\endcsname\relax
2290 \pgfplotswarning{lua colormap unavailable}{#1}\pgfeov%
2291 \expandafter\gdef\csname pgfplotscolormapfindpiecewiseconst@precomputed@warn@LUA@#1\endcsname{1}%
2292 \fi
2293 }%
2294
2295 \def\pgfplotscolormapfindpiecewiseconst@precomputed@[#1:#2][#3]#4#5{%
2296 \pgfplotscolormapassertexists{#5}%
2297 \begingroup
2298 \pgfplotscolormapfind@transform[#1:#2][#3]{#4}{#5}%
2299 \let\pgfplotscolormapfind@transformedx=\pgfmathresult
2300 %
2301 % Now, we have it in [0,1000]. Find the correct interval:
2302 % In principle, we could easily find the correct interval. But the
2303 % native approach has one distinct disadvantage: we will never
2304 % assign the rightmost color unless #4=1000! That means that our
2305 % colormap is not used entirely.
2306 %
2307 % I decided to enlarge the colormap artificially such that the
2308 % rightmost color receives its own interval.
2309 %
2310 % To this end, I recompute the coordinates at which colors "live".
2311 % The operations sounds more involved than it is: I simply need a NEW mesh width locally
2312 % inside of this function. The new mesh width H can be computed as
2313 % follows, assuming that the OLD colormap has mesh width h.
2314 %
2315 % H := 1000/ (N-1)
2316 %
2317 % N := n+1
2318 % n := 1000/h + 1 = \pgfplotscolormapsizeof{#5}
2319 %
2320 % what I really need is:
2321 % 1/H = N/1000 = (1000 h^{-1} +1)/ 1000 = h^{-1} + 1/1000
2322 %
2323 \pgfplotscolormapifisuniform{#5}{%
2324 %
2325 \expandafter\ifx\csname pgfpl@cm@#5@X@scale@order@z\endcsname\pgfutil@empty%
2326 % compute 1/H here:
2327 \pgfmathadd@{\csname pgfpl@cm@#5@invh\endcsname}{0.001}%
2328 \let\pgfplots@piecewiseconst@invh=\pgfmathresult%
2329 \else
2330 % disable the extra interval
2331 \expandafter\let\expandafter\pgfplots@piecewiseconst@invh\csname pgfpl@cm@#5@invh\endcsname
2332 \fi
2333 \pgfmathmultiply@{\pgfplotscolormapfind@transformedx}{\pgfplots@piecewiseconst@invh}%
2334 \let\pgfplotscolormapfind@transformedx@divh=\pgfmathresult
2335 % assign \pgfplotscolormapfind@intervalno := \pgfmathresult
2336 % without '.0' suffix:
2337 \expandafter\pgfplotscolormap@floor\pgfmathresult\relax
2338 % Step 2: interpolate the desired RGB value using vector valued
2339 % interpolation on the identified interval.
2340 \c@pgf@counta=\pgfplotscolormapfind@intervalno\relax
2341 }{%
2342 % the same idea can also be applied to non-uniform grids.
2343 % However, it is more involved here.
2344 %
2345 % My idea is that I add an extra interval of length 'h' at the right end of
2346 % the domain, i.e. I enlarge the domain to [0,1000+h].
2347 %
2348 % To this end, I map the input number linearly from
2349 % [0,1000] -> [0,1000+h]
2350 % using k(t) = (1000+h)/1000 * t
2351 %
2352 % Note that k(t) = 1/ pgfpl@cm@#5@X@scale@order@z
2353 %
2354 % and search in the existing X coordinates of the colormap.
2355 % Note that these X coordinates actually do not contain the
2356 % artificial rightmost boundary point at 1000+h. But that is
2357 % ok, we plan to assign COLOR(1000+h) := COLOR(1000) anyway.
2358 %
2359 % Naturally, some values 'k(t)' will be BEYOND '1000'. In this
2360 % case, we simply use the rightmost interval and are done with
2361 % it.
2362 %
2363 % compute k(t):
2364 \ifdim\csname pgfpl@cm@#5@X@scale@order@z\endcsname pt>0pt
2365 \pgfmathadd@{1000}{\csname pgfpl@cm@#5@h\endcsname}%
2366 \pgf@xa=\pgfmathresult pt %
2367 \divide\pgf@xa by1000 %
2368 \edef\pgfplotscolormapfind@map@to@extra@interval{\pgf@sys@tonumber\pgf@xa}%
2369 %
2370 \pgfmathmultiply@{\pgfplotscolormapfind@transformedx}{\pgfplotscolormapfind@map@to@extra@interval}%
2371 \let\pgfplotscolormapfind@transformedx@=\pgfmathresult
2372 \else
2373 % disable the extra interval
2374 \let\pgfplotscolormapfind@transformedx@=\pgfplotscolormapfind@transformedx
2375 \fi
2376 %
2377 % search k(t) in the original X values.
2378 \pgfplotsarraybinarysearch{pgfpl@cm@#5@X}{\pgfplotscolormapfind@transformedx@}{0}{\pgfplotscolormapsizeof{#5}}%
2379 \c@pgf@counta=\pgfplotsretval\relax
2380 \ifnum\c@pgf@counta<0
2381 % as per definition of \pgfplotsarraybinarysearch, a
2382 % negative result indicates the "insertion point" ...
2383 \c@pgf@counta=-\c@pgf@counta
2384 % ... plus one.
2385 \advance\c@pgf@counta by-1
2386 %
2387 % But we do not WANT the insertion point! We want the LEFT
2388 % interval boundary!
2389 \advance\c@pgf@counta by-1
2390 \fi
2391 %\pgfplotscolormapserializeXtomacro{#5}\XXX
2392 %\message{k(\pgfplotscolormapfind@transformedx) = \pgfplotscolormapfind@transformedx@. Searching for value in X=(\XXX) resulted in \pgfplotsretval, and the index to use is \the\c@pgf@counta.^^J}%
2393 }%
2394 %
2395 \ifnum\c@pgf@counta=\pgfplotscolormapsizeof{#5}\relax
2396 % we have artificially increased the "h" (see the comments
2397 % above) -- meaning that this 'if' can happen.
2398 % ->Map the rightmost point to the rightmost interval:
2399 \advance\c@pgf@counta by-1
2400 \fi
2401 %
2402 %\message{mapping [#1,#2] -> [0,\pgfplotscolormaprange] yielded phi = \pgfplotscolormapfind@transformedx, situated in interval no \the\c@pgf@counta/\pgfplotsarraysizeof{pgfpl@cm@#5}.^^J}%
2403 \pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5}\to\pgfplotscolormapfind@rgb@LEFT
2404 \let\pgfmathresult=\pgfplotscolormapfind@rgb@LEFT
2405 \pgfmath@smuggleone\pgfmathresult
2406 \endgroup
2407 }
2408
2409 \def\pgfplotscolormap@floor#1.#2\relax{%
2410 \ifdim0.#2pt>0.999pt
2411 % ok, it is ALMOST one more! Take this as rounding inaccuracy
2412 \c@pgf@counta=#1\relax
2413 \advance\c@pgf@counta by1
2414 \edef\pgfplotscolormapfind@intervalno{\the\c@pgf@counta}%
2415 \else
2416 \def\pgfplotscolormapfind@intervalno{#1}%
2417 \fi
2418 }%
2419
2420 \def\pgfplotscolormap@floor@unforgiving#1.#2\relax{%
2421 \def\pgfplotscolormapfind@intervalno{#1}%
2422 }%
2423
2424 % Performs a direct color access into color map '#2' using an index
2425 % '#1'.
2426 %
2427 % #1: an index in the range 0 ... len(#2)-1.
2428 % If it does not match, it will be pruned. If #1 is a real number, it
2429 % will be truncated.
2430 % #2: a color map name.
2431 %
2432 % The resulting RGB value will be written to \pgfmathresult.
2433 \def\pgfplotscolormapgetindex#1#2{%
2434 \pgfplotscolormapassertexists{#2}%
2435 \begingroup
2436 \pgfmathfloatparsenumber{#1}%
2437 \expandafter\pgfmathfloattoint\expandafter{\pgfmathresult}%
2438 %\afterassignment\pgfplots@gobble@until@relax
2439 \c@pgf@counta=\pgfmathresult\relax
2440 \ifnum\c@pgf@counta<0
2441 \c@pgf@counta=0
2442 \else
2443 \pgfplotsarraysizetomacro{pgfpl@cm@#2}\to\pgfplotscolormapgetindex@
2444 \ifnum\c@pgf@counta<\pgfplotscolormapgetindex@\relax
2445 \else
2446 \c@pgf@counta=\pgfplotscolormapgetindex@\relax
2447 \advance\c@pgf@counta by-1
2448 \fi
2449 \fi
2450 \pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#2}\to\pgfmathresult
2451 \pgfmath@smuggleone\pgfmathresult
2452 \endgroup
2453 }
2454
2455 % Invokes one of \pgfplotscolormapfind,
2456 % \pgfplotscolormapfindpiecewiseconst, or \pgfplotscolormapgetindex,
2457 % depending on the value of '/pgfplots/colormap access'.
2458 \def\pgfplotscolormapaccess[#1:#2]{%
2459 \pgfutil@ifnextchar[{%
2460 \pgfplotscolormapaccess@precomputed[#1:#2]%
2461 }{%
2462 \pgfplotscolormapaccess@precomputed[#1:#2][]%
2463 }%
2464 }
2465 \def\pgfplotscolormapaccess@precomputed[#1:#2][#3]#4#5{%
2466 \if m\pgfplots@colormap@access
2467 % colormap access=map
2468 \pgfplotscolormapfind@precomputed[#1:#2][#3]{#4}{#5}%
2469 \else
2470 \if c\pgfplots@colormap@access
2471 % colormap access=piecewise constant
2472 \pgfplotscolormapfindpiecewiseconst@precomputed[#1:#2][#3]{#4}{#5}%
2473 \else
2474 % colormap access=direct
2475 \pgfplotscolormapgetindex{#4}{#5}%
2476 \fi
2477 \fi
2478 }%
2479
2480 \pgfutil@definecolor{mapped color}{rgb}{0,0,0}% make sure this color exists. It will be overwritten if needed.
2481 % ATTENTION: replicated in pgfplots.code.tex :
2482 \pgfplotscreatecolormap{hot}{color(0cm)=(blue); color(1cm)=(yellow); color(2cm)=(orange); color(3cm)=(red)}
2483
2484
2485 \def\pgfplotspointmetatransformedrange{0:1000}
2486
2487 % Defines the 'mapped color' on the basis of
2488 % the current color map.
2489 %
2490 % #1: is the value which should be mapped into the color map; it
2491 % is expected in the range [0,1000] (like point meta).
2492 \def\pgfplotscolormapdefinemappedcolor#1{%
2493 \expandafter\pgfplotscolormapaccess\expandafter[\pgfplotspointmetatransformedrange]%
2494 [1.0]%
2495 {#1}%
2496 {\pgfkeysvalueof{/pgfplots/colormap name}}%
2497 %\message{Color for current point is RGB '\pgfmathresult' (determined using meta 'phi(\pgfplotspointmeta) = \pgfplotspointmetatransformed')^^J}%
2498 \def\pgfplots@loc@TMPb{\pgfutil@definecolor{mapped color}{\csname pgfpl@cm@\pgfkeysvalueof{/pgfplots/colormap name}@colspace\endcsname}}%
2499 \expandafter\pgfplots@loc@TMPb\expandafter{\pgfmathresult}%
2500 }%