1.12.1 Custom color mappings

The default mapping used between values of $$c_1$ and color is a grayscale mapping. This is scaled such that the smallest value of $c_1$ in the map corresponds to black, and largest value corresponds to white. 

Alternatively, the user can supply any algebraic expressions for converting values of 

$c_1$ into colors. Moreover, these custom color mappings need not be one-parameter mappings depending only on a single variable $c_1$, but can depend on up to four quantities $c_1$, $c_2$, $c_3$ and $c_4$. This makes it possible, for example, to represent both the amplitude and complex phase of a quantity in a single color map. 

Pyxplot’s {\tt colormap}\index{colormap plot style@{\tt colormap} plot style}\index{plot styles!colormap@{\tt colormap}} plot style takes between three and seven columns of data, which may be supplied either from one or more function(s), or from a data file. If data is read from a data file, then the first two columns of output data are assumed to contain the respective positions of each datapoint along the 

$x$-axis and the $y$-axis. The next column contains the value $c_1$, and may be followed by up to three further optional values $c_2$, $c_3$ and $c_4$. 

In the case where one or more function(s) are supplied, they are assumed to be functions of both 

$x$ and $y$, and are sampled at a grid of points in the $(x,y)$ plane; the first supplied function returns the value $c_1$, and may be followed by up to three further optional functions for $c_2$, $c_3$ and $c_4$.. 

The color mapping is set using the {\tt set colormap} command\index{set colormap command@{\tt set colormap} command}, which takes an algebraic expression which should be a function of the variables {\tt c1}, {\tt c2}, {\tt c3} and {\tt c4}. This should evaluate either to a color object or a number (in which case a color is drawn from the current palette). 

\begin{verbatim} 
set colormap <expr> [ mask <expr> ]
\end{verbatim}

\noindent If the optional mask expression is supplied, then any areas in a color map where this expression evaluates to false (e.g.\  zero) are made transparent. The following color mapping, which is the default, produces a grayscale color mapping of the third column of data supplied to the {\tt colormap}\index{colormap plot style@{\tt colormap} plot style}\index{plot styles!colormap@{\tt colormap}} plot style; further columns of data, if supplied, are not used: 

\begin{verbatim} 
set c1range [*:*] renormalise noreverse
set colormap gray(c1)
\end{verbatim}

The {\tt set c<n>range} command\index{set c<n>range command@{\tt set c<n>range} command} command specifies how the values of 

$c_n$ are processed before being used in the expressions supplied to the {\tt set colormap} command\index{set colormap command@{\tt set colormap} command}. It has the following syntax: 

\begin{verbatim} 
set c<n>range [ <range> ]
              [ reversed | noreversed ]
              [ renormalise | norenormalise ]
\end{verbatim}

\noindent If the {\tt renor\- malise} option is specified, then the values of 

$c_n$ at each point in the data grid are first scaled into the range zero to one. This is often useful, since the color components passed to the {\tt rgb()}, {\tt gray()}, {\tt hsb()} and {\tt cmyk()} functions must be in this range. Thus, in the example given above, the lowest value of $c_1$ corresponds to black (i.e.\  brightness 0), and the highest value corresponds to white (i.e.\  brightness 1). If an explicit range is specified to the {\tt set c<n>range} command, then the upper limit of this range maps to the value one, and the lower limit maps to the value zero. An asterisk ({\tt *}) means that the lowest or highest value found in the map is substituted. The mapping is inverted if the {\tt reverse} option is specified, such that the upper limit maps to zero, and the lower limit maps to one. Intermediate values are scaled either linearly or logarithmically, and these behaviours can be selected with the following commands: 

\begin{verbatim} 
set logscale c1
set linearscale c1
\end{verbatim}

In the example below, a color map of the function 

$f(z)=3x^2/(x^3+1)$ is made, using hue to represent the magnitude of $f(z)$ and saturation to represent the complex argument of $f(z)$: 

\vspace{2mm} \input{examples/tex/ex_ branch_ cuts_1.tex} \vspace{2mm} 

\centerline{\includegraphics[width=8cm]{examples/eps/ex_ branch_ cuts}} 

In the next example, three circular pools of red, green, and blue illumination are overlapped to show how colors mix together: 

\vspace{2mm} \input{examples/tex/ex_ spectrum_ colmix1_1.tex} \vspace{2mm} 

\centerline{\includegraphics[width=8cm]{examples/eps/ex_ spectrum_ colmix1}} 

The same is possible with CMYK colors, to demonstrate how substractive color mixing works: 

\vspace{2mm} \input{examples/tex/ex_ spectrum_ colmix2_1.tex} \vspace{2mm} 

\centerline{\includegraphics[width=8cm]{examples/eps/ex_ spectrum_ colmix2}} 

The function {\tt colors.wavelength(wlen,normalisation)} provides a color representation of any given wavelength of light, useful for producing representations of the electromagnetic spectrum: 

\vspace{2mm} \input{examples/tex/ex_ spectrum_1_1.tex} \vspace{2mm} 

\centerline{\includegraphics[width=8cm]{examples/eps/ex_ spectrum_1}} 

The function {\tt colors.spectrum(spectrum,normalisation)} takes a function as its first input, which should return a spectral energy distribution (in arbitrary units) as a function of wavelength. In this example, we show the colors of blackbodies of different temperatures. We renormalise their brightnesses by 

$T^-4$ to avoid saturating hot blackbodies to white: 

\vspace{2mm} \input{examples/tex/ex_ spectrum_ bbcol_1.tex} \vspace{2mm} 

\centerline{\includegraphics[width=8cm]{examples/eps/ex_ spectrum_ bbcol}} 

As a final example, we use this function to plot the interference pattern seen when a wedge of stressed plastic, a birefrigent material, is viewed between crossed polars: 

\vspace{2mm} \input{examples/tex/ex_ spectrum_ biref_1.tex} \vspace{2mm} 

\centerline{\includegraphics[width=8cm]{examples/eps/ex_ spectrum_ biref}} 

$