Skip to main content

Algorithmically generate categorical color palettes

Project description

Glasbey logo

pypi_version License build_status Coverage Docs

Glasbey Categorical Color Palette Tools

The glasbey library allows for the algorithmic creation of colour palettes designed for use with categorical data using techniques from the paper Colour Displays for Categorical Images by Glasbey, Heijden, Toh and Gray. You don’t need to worry about the technical details however – the glasbey library is easy to use.

It is quite common to require a colour palette for some categorical data such that each category has a visually distinctive colour. Usually one relies upon predefined colour palettes such as those from ColorBrewer, or provided by your plotting library of choice. Unfortunately such palettes do not always meet your needs: perhaps they don’t have enough distinct colours and you don’t want to re-use or cycle the palette; perhaps you have specific constraints you want to apply to get a certain look to your palette. Fortunately we can use math and perceptual colour spaces to create new palettes that maximize the perceptual visual distinctiveness of colours within constraints. It is also easy to extend an existing palette, or seed a created palette with some initial colours (perhaps your company or institutions colours). Lastly, glasbey makes it easy to generate block palettes, suitable for working with hierarchical categories.

Create categorical palettes

Glasbey basic palette example

or constrain the palette options (e.g. to muted colours)

Glasbey muted palette example

or extend existing palettes

Glasbey extending tab10 example

or create block categorical palettes

Glasbey block palette example

Basic Usage

Creating new categorical colour palettes is as easy as single function call.

import glasbey

# Create a categorical palette with 15 colours
glasbey.create_palette(palette_size=15)
# Create a muted palette with 12 colours
glasbey.create_palette(palette_size=12, lightness_bounds=(20, 40), chroma_bounds=(40, 50))

It is also easy to extend an existing palette, or create a new palette from some seed colours.

import glasbey

# Add an extra 5 colours to matplotlib's tab10 palette
glasbey.extend_palette("tab10", palette_size=15)
# Seed a palette with some initial colours
glasbey.extend_palette(["#2a3e63", "#7088b8", "#fcaf3e", "#b87088"], palette_size=8)

Installation

Glasbey requires:

  • numba

  • numpy

  • colorspacious

  • matplotlib

Glasbey can be installed via pip:

pip install glasbey

To manually install this package:

wget https://github.com/lmcinnes/glasbey/archive/main.zip
unzip main.zip
rm main.zip
cd glasbey-main
python setup.py install

Acknowledgements

This library is heavily indebted to the original glasbey library by Sergey Alexandrov.

References

  1. Glasbey, C., van der Heijden, G., Toh, V. F. K. and Gray, A. (2007), Colour Displays for Categorical Images. Color Research and Application, 32: 304-309

  2. Luo, M. R., Cui, G. and Li, C. (2006), Uniform Colour Spaces Based on CIECAM02 Colour Appearance Model. Color Research and Application, 31: 320–330

License

Glasbey is MIT licensed. See the LICENSE file for details.

Contributing

Contributions are more than welcome! If you have ideas for features of projects please get in touch. Everything from code to notebooks to examples and documentation are all equally valuable so please don’t feel you can’t contribute. To contribute please fork the project make your changes and submit a pull request. We will do our best to work through any issues with you and get your code merged in.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

glasbey-0.3.0.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

glasbey-0.3.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file glasbey-0.3.0.tar.gz.

File metadata

  • Download URL: glasbey-0.3.0.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for glasbey-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8f2c26cc7bb5ae2b8cee7c9c93b28d0edabf5e617a0f152c7519fa981ec79cda
MD5 720c20a42b60a092fa922f72b5b4818b
BLAKE2b-256 76f0d7bf369524811c8bf8ac81f75ae2b2ef1c4666487d9448ca0c99513857a6

See more details on using hashes here.

File details

Details for the file glasbey-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: glasbey-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for glasbey-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f098fc3b884f02a7f8d4d0ca95f36d719d5a566c2deb6e4ae2bb5ff1109a3c91
MD5 5469f4c08c7cd656105f433d0d28b534
BLAKE2b-256 06833bdfdf95ee8a3a55b93ebccea61814b800dc3b4f516bbf9e60620fc3d4af

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page