{"id":9590,"library":"cmap","title":"cmap: Scientific Colormaps for Python","description":"cmap provides a collection of scientific colormaps for Python, focusing on perceptual uniformity and colorblind-friendliness. It bundles various colormaps like Crameri, Tol, Viridis, and many others, offering a unified API to access and manipulate them. The library is actively maintained with frequent minor releases, currently at version 0.7.2.","status":"active","version":"0.7.2","language":"en","source_language":"en","source_url":"https://github.com/pyapp-kit/cmap","tags":["colormap","scientific","visualization","matplotlib","image-processing"],"install":[{"cmd":"pip install cmap","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Fundamental for numerical operations and array handling.","package":"numpy","optional":false},{"reason":"Provides color science utilities and color conversions.","package":"colorio","optional":false},{"reason":"Used for image processing tasks related to colormap generation and manipulation.","package":"scikit-image","optional":false},{"reason":"Required for the convenience method `Colormap.to_mpl()` to convert `cmap` colormaps into Matplotlib colormap objects.","package":"matplotlib","optional":false}],"imports":[{"symbol":"Colormap","correct":"from cmap import Colormap"},{"symbol":"get_cmap","correct":"from cmap import get_cmap"}],"quickstart":{"code":"import numpy as np\nimport matplotlib.pyplot as plt\nfrom cmap import get_cmap, Colormap\n\n# Get a colormap by name using the utility function\nmy_cmap = get_cmap(\"viridis\")\n\n# Or, access namespaced colormaps directly\n# my_cmap = Colormap.scientific.viridis\n\n# Colormap objects are callable with normalized data [0, 1] or raw data\ndata = np.linspace(0, 1, 256) # Example data\ncolors_rgba = my_cmap(data) # Returns (N, 4) array of RGBA floats\n\n# Convert to a Matplotlib colormap for seamless integration with plotting\nmpl_cmap = my_cmap.to_mpl()\n\n# Example usage with Matplotlib\nfig, ax = plt.subplots(figsize=(6, 1))\nplt.imshow([np.arange(256)], cmap=mpl_cmap, aspect='auto')\nplt.colorbar(ax.images[0], orientation='horizontal')\nplt.title(f\"Example Colormap: {my_cmap.name}\")\nplt.axis('off')\nplt.show()","lang":"python","description":"This quickstart demonstrates how to fetch a colormap using `get_cmap`, convert data to RGBA colors, and integrate the `cmap` colormap with Matplotlib for visualization via the `to_mpl()` method."},"warnings":[{"fix":"Upgrade to Python 3.9 or newer (e.g., `python -m pip install --upgrade python` or update your environment).","message":"Python 3.8 support was dropped in `cmap` version 0.6.0. Users on Python 3.8 or older will encounter errors or be unable to install recent versions.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Review any code that depends on exact `crameri` color values when upgrading from versions prior to 0.5.0. Consider pinning `cmap<0.5.0` if strict adherence to old `crameri` maps is required.","message":"The `crameri` colormaps were updated to version 8 in `cmap` v0.5.0. If you relied on pixel-perfect color values for `crameri` colormaps from older versions, these may have changed slightly.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Always use `get_cmap(\"name\")` for general access, or explicitly specify the namespace like `Colormap.scientific.viridis` when you know the colormap's location.","message":"While many colormaps can be accessed via `cmap.get_cmap(\"name\")`, some are organized into namespaces (e.g., `cmap.scientific.viridis`, `cmap.QUALITATIVE.tol.bright`). Attempting to access `cmap.name` directly for a namespaced colormap will result in an `AttributeError`.","severity":"gotcha","affected_versions":"all"},{"fix":"Consult the documentation for the specific colormap to understand its required parameters. For example, `my_parametrized_cmap = Colormap.get_cmap('my_param_map', arg1=value1, arg2=value2)` or `Colormap.linear_segmented(colors=['red', 'blue'])`.","message":"Some colormaps in `cmap` are 'parametrized' and require keyword arguments during instantiation (e.g., `Colormap.linear_segmented(...)`). If you try to instantiate these without the required arguments, a `TypeError` will be raised.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Use `from cmap import get_cmap; my_cmap = get_cmap('my_colormap_name')` or access through its specific namespace, e.g., `from cmap import Colormap; my_cmap = Colormap.scientific.my_colormap_name`.","cause":"Trying to access a colormap directly as an attribute of the top-level `cmap` module or `Colormap` class without using `get_cmap` or the correct namespace.","error":"AttributeError: module 'cmap' has no attribute 'my_colormap_name'"},{"fix":"Ensure `matplotlib` is correctly installed in your environment: `pip install matplotlib` or `pip install cmap` without `--no-deps`.","cause":"Although `matplotlib` is a direct dependency, this error can occur if `cmap` was installed with `--no-deps`, if your Python environment is corrupted, or if `matplotlib` failed to install properly.","error":"ModuleNotFoundError: No module named 'matplotlib'"},{"fix":"Check the colormap's documentation or source for expected parameters. Pass the required keyword arguments, e.g., `get_cmap('my_parametrized_colormap', segment_colors=['red', 'green', 'blue'])`.","cause":"Attempting to create or retrieve a parametrized colormap without providing its required keyword arguments.","error":"TypeError: Colormap 'my_parametrized_colormap' expects keyword arguments: ['segment_colors']"}]}