Library with colormaps for C++. Quick start: #include <cppcolormap.h>
, that's about it. Note that the library depends on xtensor. Its installation and use are equally straightforward.
Disclaimer
This library is free to use under the GPLv3 license. Any additions are very much appreciated, in terms of suggested functionality, code, documentation, testimonials, word of mouth advertisement, .... Bug reports or feature requests can be filed on GitHub. As always, the code comes with no guarantee. None of the developers can be held responsible for possible mistakes.
Download: .zip file | .tar.gz file.
(c - GPLv3) T.W.J. de Geus (Tom) | tom@geus.me | www.geus.me | github.com/tdegeus/cppcolormap
- Usage from C++
- Usage from Python
- Available colormaps
- Matplotlib
- Monochromatic colormaps
- Available color-cycles
The library is header only. This means that one has to only include the header-file cppcolormap.h
. Really, that's it!
To be able to set the include path semi-automatic, one can choose to 'install' cppcolormap. To do this using CMake:
-
Proceed to a (temporary) build directory. For example
$ cd /path/to/cppcolormap/build
-
'Build' cppcolormap
$ cmake .. $ make install
The main interface is with two functions:
#include <cppcolormap.h>
int main ()
{
std::cout << cppcolormap::colormap("Reds") << std::endl;
std::cout << cppcolormap::colorcycle("tue") << std::endl;
return 0;
}
Lists of colormaps and color-cycles can be found below.
The colormaps are stored as a matrix whereby each row contains the (R,G,B) colors. Each color value has a range [0..1]
. The number of colors varies from map to map, but can be interpolated by specifying the number of colors you want:
#include <cppcolormap.h>
int main ()
{
std::cout << cppcolormap::colormap("Reds", 256) << std::endl;
return 0;
}
Note that the colorcycles are not interpolatable. Consequently the functions do have a size option. Note also that the colormaps can also be called directly, e.g.
#include <cppcolormap.h>
int main ()
{
std::cout << cppcolormap::Reds() << std::endl;
std::cout << cppcolormap::tue() << std::endl;
return 0;
}
Clone the repository and then run:
# if you are using Python 2.x
python setup.py build
python setup.py install
# if you are using Python 3.x
python3 setup.py build
python3 setup.py install
There are two functions, each returns a 2-d NumPy array:
import cppcolormap as cmap
# number of colors in the colormap (optional, may be omitted)
N = 256
# specify the colormap as string
cols = cmap.colormap("Reds",N)
cols = cmap.colorcycle("tue",N)
# or call the functions directly
cols = cmap.Reds(N)
cols = cmap.tue(N)
(see lists of colormaps and color-cycles below).
To find the closest match of each color of a colormap in another colormap you can use:
xt::xtensor<size_t,1> idx = cppcolormap::match(cmap1, cmap2);
// use weight factors for a better visual match
xt::xtensor<size_t,1> idx = cppcolormap:match_visual(cmap1, cmap2);
Note that each colormap can be flipped by appending the name by "_r"
- Accent
- Dark2
- Paired
- Spectral
- Pastel1
- Pastel2
- Set1
- Set2
- Set3
- Blues
- Greens
- Greys
- Oranges
- Purples
- Reds
- BuPu
- GnBu
- PuBu
- PuBuGn
- PuRd
- RdPu
- OrRd
- RdOrYl
- YlGn
- YlGnBu
- YlOrRd
- BrBG
- PuOr
- RdBu
- RdGy
- RdYlBu
- RdYlGn
- PiYG
- PRGn
Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State University.
Licensed under the Apache License, Version 2.0
- magma
- inferno
- plasma
- viridis
Copyright (c) New matplotlib colormaps by Nathaniel J. Smith, Stefan van der Walt, and in the case of viridis) Eric Firing.
Licensed under the under the CC0 license / public domain dedication.
- White
- Grey
- Black
- Red
- Blue
See this site
- xterm
The following colors and color-cycles are based on the corporate color scheme of the Eindhoven University of Technology.
- tue
- tuedarkblue
- tueblue
- tuelightblue
- tuewarmred