1.12 Colour Maps

Colour maps provide a graphical means of producing two-dimensional representations of $(x,y,z)$ surfaces, or equivalently of producing maps of the values $z(x,y)$ of functions of two variables. Each point in the $(x,y)$ plane is assigned a colour which indicates the value $z$ associated with that point. In the following Section, we refer to the third coordinate as $c$ rather than $z$, to distinguish it from the third axes of three-dimensional plots1.

The default mapping used between values of $c$ and colour is a greyscale mapping, such that the smallest value of $c$ in any given colour map corresponds to black, and largest value corresponds to white. More generally, however, the user can supply any algebraic expressions for the RGB, HSB or CMYK components of the colours to be used, and even specify a mask such that some parts of the colour map appear transparent. Moreover, these custom colour mappings need not be one-parameter mappings depending only upon a single variable $c$, but can depend on up to four quantities $c_1$, $c_2$, $c_3$ and $c_4$.

PyXPlot’s colourmap plot style takes between three and seven columns of data, which may be supplied either from one or more function(s), or from a datafile. If data is read from a datafile, 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.

In the following simple example, a colour map of the complex argument of the Riemann zeta function $\zeta (z)$ is produced, taking the $(x,y)$ plane to be an Argand plane in which each point corresponds to a value of $z$, with $x$ being the real axis, and $y$ being the imaginary axis:

set numerics complex
set nokey
set size 8 square
set samples grid 400x400
set c1range[-pi:pi]
set c1format "$%s$\backslash $pi$"%(c/pi)
plot [-20:6][-13:13] arg(zeta(x+i*y)) with colourmap

\includegraphics[width=8cm]{examples/eps/ex_zeta_arg}

The command set samples grid command sets the dimensions of the grid of samples – or pixels – taken of the input functions. If either value is replaced with an asterisk (*) then the current number of samples set in the set samples command is substituted.

If a datafile is supplied to the colourmap plot style, then the datapoints need not lie on the specified regular grid, but are first re-sampled onto this grid using the interpolation method specified using the set samples interpolate command (see Section 5.7). Three methods are available. NearestNeighbour uses the values of $c_1$$c_4$ associated with the datapoint closest to each grid point, producing colour maps which look like Voronoi diagrams. InverseSquare interpolation returns a weighted average of the supplied datapoints, using the inverse squares of their distances from each grid point as weights. MonaghanLattanzio interpolation uses the weighting function of Monaghan & Lattanzio (1985) which is described further in Section 5.7).

In the following example, a colour map of a quadrupole is produced using four input datapoints:

set nokey
set size 8 square
set samples grid 200x200 interpolate InverseSquare
plot [-4:4][-4:4] ’–’ with colourmap
-1 -1 1
-1 1 -1
1 -1 -1
1 1 1
END

\includegraphics[width=8cm]{examples/eps/ex_quadrupole}

Footnotes

  1. When colour maps are plotted on three-dimensional graphs, they appear in a flat plane on one of the back faces of the plot selected using the axes modifier to the plot command, and the c-axes associated with each are entirely independent of the plot’s z-axis.