Color management
GRUtils uses various color sets for different purposes: color schemes for the general design of the plots, continuous colormaps to represent numeric data in a color scale, and a set of predefined colors with maximum contrast that are used to distinguish different data series in the same plot. Moreover, there is a space available for arbitrary user-defined colors based on RGB codes.
Color scheme
Color schemes are based on a monochromatic scale between a "foreground" and a "background" color (e.g. black and white), and a set of basic or "accent" colors that approximate the six standard secondary colors: red, green, blue, cyan, yellow and magenta.
By default there are light and dark flavours of both standard and solarized schemes, whose background, foreground and the other basic colors can be seen below.
Colormaps
Colormaps are based on a scale of 256 contiguous colors that can be used to represent numeric ranges. GRUtils uses the "Viridis" colormap by default (see below), with the option of changing to any of the 48 built-in colormaps of GR.
High-contrast color set
When various geometries of the same kind are included in the same plot (e.g. line plots with multiple data series), they are drawn using the predefined sequence of colors that is shown below – unless a specific color is explicitly set by the user. That sequence has 20 different colors that approach Kelly’s list of colors with maximum contrast (leaving aside white and black), and the order of the first colors is reminiscent of the sequence used by GNU Octave or Matlab.
User-defined colors
Custom colors can be defined as hexadecimal codes joining the values of 8-bit RGB channels. E.g. the number #FF6600 defines a bright orange color (R = #FF, G = #66, B = #00). Those codes can be defined directly as integer numbers, or from the RGB values normalized between 0 and 1, with the function color
(unexported). For instance, the code #FF6600 can be defined in any of the following ways:
0xff6600 # UInt32 number, equivalent to 16_737_792
GRUtils.color(1, 0.4, 0) # R = 1, G = 0.4, B= 0
The RGB channels in those hexadecimal color codes are assumed to be "word-ordered" in a little-endian system, i.e. the red-green-blue bytes are ordered from the most to the least significant. Take care of the byte order if you use integer color codes calculated from other sources.
The color system of GR, used by GRUtils, has room for nearly 1,000 colors defined ad hoc by the user in each session – let aside the color sets that have already been commented. There are more than 16 million of possible RGB combinations, although in practice you will never need more than a small fraction of the space for user-defined colors.
Transparency
By default, colors are assumed to be "opaque", but an alpha level of transparency can be added to user-defined colors: this is a value that can vary between 0
(fully transparent) and 1
(fully opaque).
Using colors with GRUtils
General scheme and color map
The general color scheme and the colormap are set globally, but they can be changed at any time during the session with the functions colorscheme
and colormap
, or chosen specifically for particular plots with colorscheme!
and colormap!
. See the documentation of those functions for more details.
Color of geometries
The high-contrast color set is managed automatically during the creation of plots, if no other colors are selected by the user. There are two ways to specify particular colors, depending on the kind of geometry:
Geometries based on lines and markers (e.g. in 2D or 3D line plots, among others), can receive a format string, as in matplotlib. Such strings may contain characters that correspond to the basic colors of the scheme:
'r'
for red,'g'
for green,'b'
for blue,'c'
for cyan,'y'
for yellow,'m'
for magenta,'w'
for the background color (white in the default scheme).'k'
for the foreground color (black in the default scheme),
Moreover, user-defined colors can be specified for the following attributes of some geometries:
linecolor
for lines,markercolor
for markers,color
for filled areas in bars, isosurfaces, etc.
This can be done during the creation of the plots, as in the following examples:
# Format string for a red line (straight)
plot(LinRange(0, 1, 10), "-r")
hold(true)
# Add a purple line (curved)
plot(exp.(LinRange(-1, 0, 10)),
linecolor=GRUtils.color(0.5, 0, 0.75))
The alpha channel of transparency can be also defined for all geometries using the keyword argument alpha
, with any value between 0 and 1.
Background colors
The background color of the areas that enclose the plot axes and legends is defined by the color scheme. By default, the outer area of the plots is either transparent or has the same background color, depending on the selected scheme (cf. colorscheme
).
The function background
can be used to change the outer background of the figure, filling it with a user-defined color and a custom transparency level. This can be also done during the creation of the plot, using the keyword arguments backgroundcolor
and backgroundalpha
. This only affects the area outside the axes and legends.