Skip to content

wolfv/cppcolormap

 
 

Repository files navigation

cppcolormap

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

Contents

Usage from C++

Installation

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:

  1. Proceed to a (temporary) build directory. For example

    $ cd /path/to/cppcolormap/build
  2. 'Build' cppcolormap

    $ cmake ..
    $ make install

Usage

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;
}

Usage from Python

Installation

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

Usage

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).

Find match

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);

Available colormaps

Note that each colormap can be flipped by appending the name by "_r"

ColorBrewer

  • 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

colorbrewer2.org

Matplotlib

  • 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.

GitHub

Monochromatic colormaps

  • White
  • Grey
  • Black
  • Red
  • Blue

Available color-cycles

Xterm

See this site

  • xterm

Eindhoven University of Technology

The following colors and color-cycles are based on the corporate color scheme of the Eindhoven University of Technology.

  • tue
  • tuedarkblue
  • tueblue
  • tuelightblue
  • tuewarmred

About

Library with colormaps for C++

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 95.1%
  • CMake 3.4%
  • Python 1.5%