Skip to main content

A library for generating color palettes with distinct colors

Project description

glasbeyish

This is a library that implements a method described in the paper "Colour Displays for Categorical Images" by Glasbey et al. for finding optimal distinct color palettes of a specified size.

Unlike the glasbey library, this library implements the simulated annealing method described in the paper rather, than the iterative method. The simulated annealing method can often give better color palettes at the expense of longer run times.

Examples

These examples can also be found in the examples.ipynb Jupyter notebook.

import numpy as np
from nice_colorsys import rgb
from glasbeyish import glasbey
from matplotlib.colors import ListedColormap

Generate a palette with 2 colors

cm = ListedColormap([c.to_rgb() for c in glasbey(2)])
cm

Two color colormap

Generate a palette with 12 colors

cm = ListedColormap([c.to_rgb() for c in glasbey(12)])
cm

Twelve color colormap

Use a seed for reproducibility

cm = ListedColormap([c.to_rgb() for c in glasbey(12, seed=485)])
cm

Twelve color colormap, created with seed 485

cm = ListedColormap([c.to_rgb() for c in glasbey(12, seed=485)])
cm

The same twelve color colormap, created with seed 485

Limit the colors that can be generated

Here, we'll try to make a bluish color palette by discarding colors too far from blue.

def color_dist(a, b):
    return np.linalg.norm(np.array(a.to_cieluv()) - np.array(b.to_cieluv()))

cm = ListedColormap([c.to_rgb() for c in glasbey(12, seed=485, limit=lambda x: color_dist(x, rgb(0, 0, 1)) < 100)])
cm

Bluish color map

Use a custom random color generator

In this example, we'll generate random colors with only blue components in the RGB color space. glasbey expects the generated colors to be in the CIELUV color space and won't automatically convert the colors from RGB to CIELUV for us, so we have to do that ourselves.

rng = np.random.default_rng()
def random_color(rng):
    return rgb(0, 0, rng.random()).to_cieluv()
    
cm = ListedColormap([c.to_rgb().safe() for c in glasbey(12, seed=485, random_color=random_color)])
cm

Blue color map

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

glasbeyish-0.1.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

glasbeyish-0.1.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file glasbeyish-0.1.1.tar.gz.

File metadata

  • Download URL: glasbeyish-0.1.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for glasbeyish-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c9db20041a4ef3c79c0b3f46a14f21cde5b33fd6e735310d9c58f54d22c6a076
MD5 773b19829f5cf685dfada0caa4daff5a
BLAKE2b-256 e05cb91580b283c3e62e14979ce8533ad42b3d07a64519942bdb543b13b3a6df

See more details on using hashes here.

Provenance

The following attestation bundles were made for glasbeyish-0.1.1.tar.gz:

Publisher: package.yml on actapia/glasbeyish

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glasbeyish-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: glasbeyish-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for glasbeyish-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0239ac207d598263a4533c3d25a47255a1a0b4c8a1e2778bfce4d7fff7c970bf
MD5 6d9e16641a2a708031fb92d6a0be0da3
BLAKE2b-256 fb6712dc23c417ebc7c124a959e3e68977b2fc6d47d6290e5affb8fa593e373f

See more details on using hashes here.

Provenance

The following attestation bundles were made for glasbeyish-0.1.1-py3-none-any.whl:

Publisher: package.yml on actapia/glasbeyish

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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