colormaps – Additional Colormaps for the Racket Plot Package
1 Using Colormaps
2 Colormaps Defined in this Package
2.1 Paul Tol’s Colormaps
2.1.1 TOL Qualitative
2.1.2 TOL Diverging
2.1.3 TOL Sequential
2.1.4 TOL Rainbow
make-tol-rainbow-colormap
2.2 Color  Brewer 2.0 Colormaps
2.2.1 CB Qualitative
2.2.2 CB Diverging
2.2.3 CB Multi-Hue Sequential
2.2.4 CB Single-Hue Sequential
3 Colormap Utilities
pp-color-map
pp-color-maps
8.12

colormaps – Additional Colormaps for the Racket Plot Package🔗ℹ

Alex Harsáyi

The plot package introduced support for color maps using the plot-pen-color-map and plot-brush-color-map and they allow producing visually atractive plots by using pre-selected colors which work well together.

Several color maps are defined inside the plot package plus additional ones can be defined using register-color-map. This package defines additional color maps to be used with the plot pakage.

1 Using Colormaps🔗ℹ

To use color maps for plots, set the a color map using plot-pen-color-map and use integer indexes for #:color argument of various plot renderers. For example, this code will produce the plot below and changing the argument of plot-pen-color-map will automatically change the colors of the plot:

(require plot)
(parameterize ([plot-pen-color-map 'set1])
  (plot (list (function sin -5 5 #:color 0)
              (function cos -5 5 #:color 1))))

image

The color-map-names function can be used to retrieve the list of installed color maps and you can use the pp-color-map and pp-color-maps functions to inspect the colors available in a color map. Here are all the colors from the 'set1 color map used in the previous plot:

image

Color maps were designed for use with the plot package, and retrieving individual colors from a color map is perhaps unnecessarily complicated. You can use ->pen-color for this purpose like so:

(match-define (list red green blue)
  (parameterize ([plot-pen-color-map 'set1])
    (->pen-color 0)))

2 Colormaps Defined in this Package🔗ℹ

2.1 Paul Tol’s Colormaps🔗ℹ

 (require colormaps/tol) package: colormaps

The color maps defined in colormaps/tol are based on Paul Tol’s color schemes, see the link for more detailed description about the design of these color maps and their intented uses.

Requiring the colormaps/tol or colormaps modules will automatically register these color maps for use.

2.1.1 TOL Qualitative🔗ℹ

Qualitative Colour Maps should be used for nominal or categorical data, where magnitude differences are not relevant, for example lines in plots. The following qualitative color maps are defined:

Tag

Name

Colors

'tol-bq

Bright

image

'tol-hcq

High Contrast

image

'tol-vq

Vibrant

image

'tol-mq

Muted

image

'tol-pq

Pale

image

'tol-dq

Dark

image

'tol-lq

Light

image

2.1.2 TOL Diverging🔗ℹ

Diverging Colour Maps should be used for data that is ordered between two extremes where the midpoint is important (e.g. positive and negative deviations from a mean value). The following diverging colour maps are defined:

Tag

Name

Colors

'tol-sd

Sunset

image

'tol-bd

BuRd

image

'tol-pd

PRGn

image

2.1.3 TOL Sequential🔗ℹ

Sequential Colour Maps should be used for data that is ordered from a low to a high value. The following sequential color maps are defined:

Tag

Name

Colors

'tol-ys

YlOrBr

image

'tol-is

Iridescent

image

2.1.4 TOL Rainbow🔗ℹ

procedure

(make-tol-rainbow-colormap color-count 
  [#:register? register? 
  #:name name]) 
  (listof (list integer? integer? integer?))
  color-count : exact-positive-integer?
  register? : boolean? = #f
  name : (or/c #f symbol?) = #f
Create and maybe register a rainbow color scheme containing exactly color-count visually distinct colors. Returns the list of the colors in the color scheme as RGB triplets.

The color scheme is constructed as described Paul Tol’s notes about sequential color schemes. For color schemes up to 29 colors, the colors are selected from a discrete color palette, for larger number of colours the colours are interpolated.

When register? is #t, the color map will be registered using register-color-map using either a generated name or an user supplied one.

name specifies the name of the color scheme to use when registering it. When #f, a default name will be created by appending the number of colors to the symbol 'tol-rainbow. For example, the default name for a 10 color rainbow will be 'tol-rainbow-10.

Here are the first 10 color schemes created by calling make-tol-rainbow-colormap with arguments from 1 to 10. The function can generate color maps with larger number of colors as well, but the larger the number of colors, the less distinct adjacent ones will be.

Tag

Colors

'tol-rainbow-1

image

'tol-rainbow-2

image

'tol-rainbow-3

image

'tol-rainbow-4

image

'tol-rainbow-5

image

'tol-rainbow-6

image

'tol-rainbow-7

image

'tol-rainbow-8

image

'tol-rainbow-9

image

'tol-rainbow-10

image

2.2 ColorBrewer 2.0 Colormaps🔗ℹ

 (require colormaps/cb) package: colormaps

The color maps defined in colormaps/cb are based on Color Brewer 2.0 color schemes, see the link for more detailed description about the design of these color maps and their intented uses. Note that the qualitative color maps provided by Color Brewer are already provided as part of the default color maps provided by the plot package itself, this module defines the sequential and diverging color schemes, as well as one additional qualitative color map.

Requiring the colormaps/cb or colormaps modules will automatically register these color maps for use.

2.2.1 CB Qualitative🔗ℹ

Qualitative Colour Maps should be used for nominal or categorical data, where magnitude differences are not relevant, for example lines in plots. The package provides one color map in this category:

Tag

Name

Colors

'cb-accent

Accent

image

2.2.2 CB Diverging🔗ℹ

Diverging Colour Maps should be used for data that is ordered between two extremes where the midpoint is important (e.g. positive and negative deviations from a mean value). Several color maps are defined for the same hue change and an appropiate color map should be used based on the number of categories in the data. For example, if there are 5 categories in the data, use the 'cb-brbg-5 color map, but for 7 categories, use the 'cb-brbg-7.

Tag

Colors

'cb-brbg-3

image

'cb-brbg-4

image

'cb-brbg-5

image

'cb-brbg-6

image

'cb-brbg-7

image

'cb-brbg-8

image

'cb-brbg-9

image

'cb-brbg-10

image

'cb-brbg-11

image

Tag

Colors

'cb-piyg-3

image

'cb-piyg-4

image

'cb-piyg-5

image

'cb-piyg-6

image

'cb-piyg-7

image

'cb-piyg-8

image

'cb-piyg-9

image

'cb-piyg-10

image

'cb-piyg-11

image

Tag

Colors

'cb-prgn-3

image

'cb-prgn-4

image

'cb-prgn-5

image

'cb-prgn-6

image

'cb-prgn-7

image

'cb-prgn-8

image

'cb-prgn-9

image

'cb-prgn-10

image

'cb-prgn-11

image

Tag

Colors

'cb-puor-3

image

'cb-puor-4

image

'cb-puor-5

image

'cb-puor-6

image

'cb-puor-7

image

'cb-puor-8

image

'cb-puor-9

image

'cb-puor-10

image

'cb-puor-11

image

Tag

Colors

'cb-rdbu-3

image

'cb-rdbu-4

image

'cb-rdbu-5

image

'cb-rdbu-6

image

'cb-rdbu-7

image

'cb-rdbu-8

image

'cb-rdbu-9

image

'cb-rdbu-10

image

'cb-rdbu-11

image

Tag

Colors

'cb-rdgy-3

image

'cb-rdgy-4

image

'cb-rdgy-5

image

'cb-rdgy-6

image

'cb-rdgy-7

image

'cb-rdgy-8

image

'cb-rdgy-9

image

'cb-rdgy-10

image

'cb-rdgy-11

image

Tag

Colors

'cb-rdylbu-3

image

'cb-rdylbu-4

image

'cb-rdylbu-5

image

'cb-rdylbu-6

image

'cb-rdylbu-7

image

'cb-rdylbu-8

image

'cb-rdylbu-9

image

'cb-rdylbu-10

image

'cb-rdylbu-11

image

Tag

Colors

'cb-rdylgn-3

image

'cb-rdylgn-4

image

'cb-rdylgn-5

image

'cb-rdylgn-6

image

'cb-rdylgn-7

image

'cb-rdylgn-8

image

'cb-rdylgn-9

image

'cb-rdylgn-10

image

'cb-rdylgn-11

image

Tag

Colors

'cb-spectral-3

image

'cb-spectral-4

image

'cb-spectral-5

image

'cb-spectral-6

image

'cb-spectral-7

image

'cb-spectral-8

image

'cb-spectral-9

image

'cb-spectral-10

image

'cb-spectral-11

image

2.2.3 CB Multi-Hue Sequential🔗ℹ

Sequential Colour Maps should be used for data that is ordered from a low to a high value, the package provides both single-hue and multi hue color maps. Several color maps are defined for the same hue change and an appropiate color map should be used based on the number of categories in the data. For example, if there are 5 categories in the data, use the 'cb-bugn color map, but for 7 categories, use the 'cb-bugn-7.

Tag

Colors

'cb-bugn-3

image

'cb-bugn-4

image

'cb-bugn-5

image

'cb-bugn-6

image

'cb-bugn-7

image

'cb-bugn-8

image

'cb-bugn-9

image

Tag

Colors

'cb-bupu-3

image

'cb-bupu-4

image

'cb-bupu-5

image

'cb-bupu-6

image

'cb-bupu-7

image

'cb-bupu-8

image

'cb-bupu-9

image

Tag

Colors

'cb-gnbu-3

image

'cb-gnbu-4

image

'cb-gnbu-5

image

'cb-gnbu-6

image

'cb-gnbu-7

image

'cb-gnbu-8

image

'cb-gnbu-9

image

Tag

Colors

'cb-orrd-3

image

'cb-orrd-4

image

'cb-orrd-5

image

'cb-orrd-6

image

'cb-orrd-7

image

'cb-orrd-8

image

'cb-orrd-9

image

Tag

Colors

'cb-pubu-3

image

'cb-pubu-4

image

'cb-pubu-5

image

'cb-pubu-6

image

'cb-pubu-7

image

'cb-pubu-8

image

'cb-pubu-9

image

Tag

Colors

'cb-pubugn-3

image

'cb-pubugn-4

image

'cb-pubugn-5

image

'cb-pubugn-6

image

'cb-pubugn-7

image

'cb-pubugn-8

image

'cb-pubugn-9

image

Tag

Colors

'cb-purd-3

image

'cb-purd-4

image

'cb-purd-5

image

'cb-purd-6

image

'cb-purd-7

image

'cb-purd-8

image

'cb-purd-9

image

Tag

Colors

'cb-rdpu-3

image

'cb-rdpu-4

image

'cb-rdpu-5

image

'cb-rdpu-6

image

'cb-rdpu-7

image

'cb-rdpu-8

image

'cb-rdpu-9

image

Tag

Colors

'cb-ylgn-3

image

'cb-ylgn-4

image

'cb-ylgn-5

image

'cb-ylgn-6

image

'cb-ylgn-7

image

'cb-ylgn-8

image

'cb-ylgn-9

image

Tag

Colors

'cb-ylgnbu-3

image

'cb-ylgnbu-4

image

'cb-ylgnbu-5

image

'cb-ylgnbu-6

image

'cb-ylgnbu-7

image

'cb-ylgnbu-8

image

'cb-ylgnbu-9

image

Tag

Colors

'cb-ylorbr-3

image

'cb-ylorbr-4

image

'cb-ylorbr-5

image

'cb-ylorbr-6

image

'cb-ylorbr-7

image

'cb-ylorbr-8

image

'cb-ylorbr-9

image

Tag

Colors

'cb-ylorrd-3

image

'cb-ylorrd-4

image

'cb-ylorrd-5

image

'cb-ylorrd-6

image

'cb-ylorrd-7

image

'cb-ylorrd-8

image

'cb-ylorrd-9

image

2.2.4 CB Single-Hue Sequential🔗ℹ

Tag

Colors

'cb-blues-3

image

'cb-blues-4

image

'cb-blues-5

image

'cb-blues-6

image

'cb-blues-7

image

'cb-blues-8

image

'cb-blues-9

image

Tag

Colors

'cb-greens-3

image

'cb-greens-4

image

'cb-greens-5

image

'cb-greens-6

image

'cb-greens-7

image

'cb-greens-8

image

'cb-greens-9

image

Tag

Colors

'cb-greys-3

image

'cb-greys-4

image

'cb-greys-5

image

'cb-greys-6

image

'cb-greys-7

image

'cb-greys-8

image

'cb-greys-9

image

Tag

Colors

'cb-oranges-3

image

'cb-oranges-4

image

'cb-oranges-5

image

'cb-oranges-6

image

'cb-oranges-7

image

'cb-oranges-8

image

'cb-oranges-9

image

Tag

Colors

'cb-purples-3

image

'cb-purples-4

image

'cb-purples-5

image

'cb-purples-6

image

'cb-purples-7

image

'cb-purples-8

image

'cb-purples-9

image

Tag

Colors

'cb-reds-3

image

'cb-reds-4

image

'cb-reds-5

image

'cb-reds-6

image

'cb-reds-7

image

'cb-reds-8

image

'cb-reds-9

image

3 Colormap Utilities🔗ℹ

 (require colormaps/utils) package: colormaps

procedure

(pp-color-map name    
  [#:width width    
  #:height height    
  #:show-text? show-text?    
  #:text-style text-style    
  #:text-size text-size])  pict?
  name : symbol?
  width : (or/c #f positive?) = #f
  height : positive? = 30
  show-text? : boolean? = #t
  text-style : text-style/c = null
  text-size : (integer-in 1 1024) = 12
Return a pict representing the color map name, one cell for each color, possibly numbered for reference.

width is the total width of the resulting picture. When f, the width is determined from the number of colors in the color map and the height of each cell. When width is a number, this will be the total width of the pict, and cells will be scalled to fit inside this width.

height is the height of the resulting picture, and the height of each individual color cell.

show-text?, when #t, will label each cell with a number representing the index of the color in the color map. This number can be passd to the #:color parameter of plot renderers to use that color.

text-style is the text style used to render the text inside each cell. Passed to the text pict constructor.

text-size is the text size used to render the text inside each cell. Passed to the text pict constructor.

For example to print the colors for the built-in 'set1 color map, to print out the colors in 'set1, use (pp-color-map 'set1):

image

procedure

(pp-color-maps names    
  [#:width width    
  #:height height    
  #:show-text? show-text?    
  #:text-style text-style    
  #:text-size text-size])  pict?
  names : ((listof symbol?) (color-map-names))
  width : (or/c #f positive?) = #f
  height : positive? = 30
  show-text? : boolean? = #t
  text-style : text-style/c = null
  text-size : (integer-in 1 1024) = 12
Return a pict representing the color maps in names, one line for each color map, along with its name.

names defaults to all installed color maps. The width, height, show-text?, text-style and text-size arguments are the same as for pp-color-map.

For example to print the color maps for the built-in 'set1 and 'set2 color maps, use (pp-color-maps '(set1 set2)):

image