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.
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))))
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:
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)))
|(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.
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:
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:
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:
(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
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.
|(require colormaps/utils)||package: colormaps|
(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
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.
(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
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.