colorcet

repository·main·Indexed 20 days ago

https://github.com/holoviz/colorcet

A collection of over 100 perceptually uniform continuous and categorical colormaps for Python-based data visualization. Designed for use with plotting libraries such as bokeh, matplotlib, holoviews, and datashader, these colormaps are based on the perceptually uniform set created by Peter Kovesi at the Center for Exploration Targeting. Includes utilities for visualizing colormaps via swatches, sine ramps, and scatter plots.

Tokens
5.7K
Snippets
21
Records
31
Agent score
69%

What's inside colorcet

  1. Overview of colorcet

    main
    Colorcet is a collection of perceptually uniform colormaps designed for use with Python plotting libraries such as bokeh, matplotlib, holoviews, and datashader. These colormaps are based on the perceptually uniform set created by Peter Kovesi at the Center for Exploration Targeting.
  2. Use Pixi tasks for development

    main

    Pixi manages development workflows through tasks (run via pixi run <task-name>) and environments (sets of packages).

    Common Development Tasks

    • List all tasks: pixi task list
    • Activate the default environment: pixi shell (similar to conda activate)
    • Sync Git tags: If working from a fork, sync tags to ensure versioning works correctly:
      pixi run sync-git-tags
    • Launch Jupyter Lab: Use the default environment to edit documentation or debug notebooks:
      pixi run lab

    Running tasks in specific environments

    You can target specific environments using the -e flag. For example, to run a task in the test-core environment:

    pixi run -e test-core <task-name>
  3. Set up the colorcet development environment

    main

    To contribute to colorcet, use pixi to manage environments and tasks. The setup process creates a default environment, installs colorcet in editable mode, and installs pre-commit for linting.

    Prerequisites

    • Git: Installed on your system.
    • GitHub Account: Required for forking and Pull Requests.
    • Pixi: Install via the official guide.

    Installation Steps

    1. Fork and Clone the repository:
      git clone https://github.com/<Your Username Here>/colorcet
    2. Initialize the environment:
      pixi run setup-dev
    NOTE

    The first run creates a pixi.lock file and a .pixi directory. Avoid placing the source directory in a cloud-synced folder (like Dropbox or OneDrive) as the .pixi directory can become very large.

    pixi run setup-dev
  4. Install the latest development release of colorcet

    main

    To test the latest features before they are officially released, you can install the development version from the pyviz channel using conda.

    conda install -c pyviz/label/dev colorcet
  5. Run linting, type checking, and tests

    main

    Maintain code quality using the following built-in tasks:

    Linting and Formatting

    colorcet uses pre-commit to lint and format code. It is installed automatically via setup-dev.

    • Run linting on all files: pixi run lint
    • Manual pre-commit commands (if installed globally):
      • pre-commit install
      • pre-commit run --all-files

    Type Checking

    Static type checking is performed using mypy:

    • Run type checker: pixi run test-type

    Testing

    • Unit Tests: Run small tests (located in colorcet/tests/) using pytest:
      pixi run test-unit
      Note: You can run these in specific Python version environments (e.g., test-39, test-312) using pixi run -e test-312 test-unit.
    • Example Tests: Executes Jupyter Notebooks in the doc/ folder using nbval to ensure they run without error:
      pixi run test-example
  6. Configure VS Code for colorcet development

    main

    To use the pixi development environment within VS Code:

    1. Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P).
    2. Run Python: Select Interpreter.
    3. Choose {'default': Pixi} from the list.

    This ensures VS Code uses the correct dependencies and Python version managed by Pixi.

  7. Overview of Colorcet colormaps

    main

    Colorcet is a collection of perceptually accurate 256-color colormaps designed for use with Python plotting libraries such as Bokeh, Matplotlib, HoloViews, and Datashader.

    It provides two primary types of colormaps:

    1. Continuous Colormaps: These are perceptually uniform, meaning each new color is equally perceptually distinct from its neighbors. They are ideal for representing numerical scales and scientific datasets where avoiding false boundaries and preserving detail is critical. Examples include fire (a perceptually uniform version of Matplotlib's hot) and rainbow4 (a version of jet).
    2. Categorical Colormaps: These are designed for discrete categories rather than numerical scales. They provide well-separated, distinct colors sampled from a perceptual space, allowing for a large number of categories to be visually distinguishable.
  8. Understand the Glasbey colormap naming convention

    main

    Colorcet uses a structured naming convention for Glasbey colormaps to allow users to specify constraints on the color space. This is useful when you need to ensure colors are visible against specific backgrounds or fall within certain hue ranges.

    Naming Pattern: glasbey_<starting_palette>[_<min|max>c_<chroma_value>][_<min|max>l_<lightness_value>][_hue_<start>_<end>]

    Components:

    • starting_palette: The initial set of colors used to seed the algorithm (e.g., bw for black/white).
    • minc_<value> / maxc_<value>: Constraints on chroma (saturation).
    • minl_<value> / maxl_<value>: Constraints on lightness.
    • hue_<start>_<end>: Constraints on the hue range (e.g., hue_150_280 for cool colors).

    Common Aliases:

    • glasbey_bw: The full CIELAB gamut (includes dark/light/gray colors).
    • glasbey: An alias for glasbey_bw_minc_20 (removes grays/low chromaticity).
    • glasbey_dark: Colors with lightness $\le$ 70 (optimized for dark backgrounds).
    • glasbey_light: Colors with lightness $\ge$ 30 (optimized for light backgrounds).
    • glasbey_warm: Colors with hues between 330° and 100°.
    • glasbey_cool: Colors with hues between 150° and 280°.
  9. Understand colormap naming conventions

    main

    Each colormap in colorcet follows a specific naming pattern that describes its properties:

    {category}_{huesequence}_{lightnessrange}_c{meanchroma}[_s{colorshift}[_r]]

    This structure allows you to identify the category, hue sequence, lightness range, mean chroma, and optional color shifts or refinements directly from the name.

  10. Understand the difference between continuous and categorical colormaps

    main

    When choosing a colormap in Colorcet, consider the nature of your data:

    • Use Continuous Colormaps when your data represents a continuous numerical scale (e.g., temperature, density, or elevation). These maps ensure that changes in data values correspond to equal changes in perceived color, preventing the 'washing out' of detail or the creation of artificial visual boundaries.
    • Use Categorical Colormaps when your data represents discrete, non-ordered groups (e.g., different species, country names, or types of objects). These maps focus on maximizing the perceptual distance between individual colors so that each category is easily recognizable.