cmap


Namecmap JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummaryScientific colormaps for python, without dependencies
upload_time2024-04-28 18:22:22
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseBSD 3-Clause License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cmap

[![License](https://img.shields.io/pypi/l/cmap.svg?color=green)](https://github.com/tlambert03/cmap/raw/main/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/cmap.svg?color=green)](https://pypi.org/project/cmap)
![Conda](https://img.shields.io/conda/v/conda-forge/cmap)
[![Python Version](https://img.shields.io/pypi/pyversions/cmap.svg?color=green)](https://python.org)
[![CI](https://github.com/tlambert03/cmap/actions/workflows/ci.yml/badge.svg)](https://github.com/tlambert03/cmap/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/tlambert03/cmap/branch/main/graph/badge.svg)](https://codecov.io/gh/tlambert03/cmap)
[![Documentation Status](https://readthedocs.org/projects/cmap-docs/badge/?version=latest)](https://cmap-docs.readthedocs.io/en/latest/?badge=latest)

Scientific colormaps for python, with no dependencies beyond numpy.

With `cmap`, you can use any of the colormaps from
[matplotlib](https://matplotlib.org/stable/tutorials/colors/colormaps.html),
[cmocean](https://matplotlib.org/cmocean/),
[colorbrewer](https://colorbrewer2.org/),
[crameri](https://www.fabiocrameri.ch/colourmaps/),
[seaborn](https://seaborn.pydata.org/tutorial/color_palettes.html), and a host
of other collections in your python code, without having to install matplotlib
or any other dependencies beyond numpy.

:book: [See the complete
catalog](https://cmap-docs.readthedocs.io/en/latest/catalog/)

There are a number of python libraries that provide or require colormaps or
basic color support, but they all either depend on matplotlib, provide a
specialized set of colormaps intended to extend those provided by matplotlib, or
roll their own colormap solution that vendors/duplicates other libraries.

`cmap` is a lightweight, library that provides a large collection of colormaps
with no dependencies beyond numpy.  It provides exports to a number of known
third-party colormap objects, allowing it to be used across a wide range of
python visualization libraries.  The intention is to provide a library that can
be used by any python library that needs colormaps, without forcing the user to
install matplotlib (while still being compatible with matplotlib and other
libraries that use matplotlib colormaps).

`cmap` is strictly typed and fully tested, with a focus on good developer
experience.

## Install

```
pip install cmap
```

```
conda install -c conda-forge cmap
```

## Usage

See [Documentation](https://cmap-docs.readthedocs.io/) for full details.

### [`cmap.Color`](https://cmap-docs.readthedocs.io/en/latest/colors/)

The `cmap.Color` object is a simple wrapper around a tuple of RGBA scalars, with
a few convenience methods for converting to other color objects.

```python
from cmap import Color

red = Color("red")  # or a variety of other "color like" inputs
```

### [`cmap.Colormap`](https://cmap-docs.readthedocs.io/en/latest/colormaps/)

The `cmap.Colormap` object is a callable that can map a scalar value (or numpy
array of values) to an RGBA color (or a numpy array of RGBA colors).  API is
intended to mimic the behavior of a
[`matplotlib.colors.Colormap`](https://matplotlib.org/stable/api/_as_gen/matplotlib.colors.Colormap.html#matplotlib.colors.Colormap)
object (without requiring matplotlib)

```python
In [1]: import cmap

# or a variety of other "colormap like" inputs
In [2]: cmap1 = cmap.Colormap(["red", "green", "blue"])

In [3]: cmap1(np.linspace(0,1,5))
Out[3]:
array([[1.        , 0.        , 0.        , 1.        ],
       [0.50393701, 0.24900417, 0.        , 1.        ],
       [0.        , 0.50196078, 0.        , 1.        ],
       [0.        , 0.24900417, 0.50393701, 1.        ],
       [0.        , 0.        , 1.        , 1.        ]])
```

Note that the input array must be normalized from 0-1, so if you're applying a colormap
to an integer array (like an image) you must apply any contrast limits and rescale to
0-1 before passing it to a `Colormap`.

## Third Party Library Support

The `cmap.Colormap` object has convenience methods that export it to a number of known
third-party colormap objects, including:

- [matplotlib](https://matplotlib.org/)
- [napari](https://napari.org/)
- [vispy](https://vispy.org/)
- [pygfx](https://pygfx.readthedocs.io/en/latest/) (& [fastplotlib](https://github.com/fastplotlib/fastplotlib))
- [plotly](https://plotly.com/python/)
- [bokeh](https://docs.bokeh.org/en/latest/)
- [altair](https://altair-viz.github.io/)
- [pyqtgraph](https://www.pyqtgraph.org/)

See [documentation](https://cmap-docs.readthedocs.io/en/latest/colormaps/#usage-with-external-visualization-libraries)
for details.

If you would like to see support added for a particular library, please open an issue or PR.

## Alternatives

Other libraries providing colormaps:

- [matplotlib](https://matplotlib.org/stable/tutorials/colors/colormaps.html)
- [seaborn](https://seaborn.pydata.org/tutorial/color_palettes.html)  (subclasses matplotlib)
- [proplot](https://proplot.readthedocs.io/en/latest/colormaps.html)  (subclasses matplotlib)
- [palettable](https://jiffyclub.github.io/palettable/) (mostly data, import doesn't depend on matplotlib, but usage largely does)
- [cmocean](https://matplotlib.org/cmocean/) (mostly data, outputs matplotlib colormaps)
- [colorcet](https://colorcet.holoviz.org/) (mostly data, usage requires either matplotlib or bokeh)
- [cmasher](https://cmasher.readthedocs.io/) (requires matplotlib)
- [cmyt](https://github.com/yt-project/cmyt) (requires matplotlib)
- [cmcrameri](https://github.com/callumrollo/cmcrameri) (requires matplotlib, wraps <https://www.fabiocrameri.ch/colourmaps/>)
- [distinctipy](https://github.com/alan-turing-institute/distinctipy)  (generates distinct color sets, only requires numpy)
- [Farrow & Ball Matplotlib](https://github.com/vork/farrowandball) (requires matplotlib)
- [mplcyberpunk](https://github.com/dhaitz/mplcyberpunk) (requires matplotlib)

## References and Further reading

- [Choosing Colormaps in Matplotlib](https://matplotlib.org/stable/tutorials/colors/colormaps.html)
- [A Better Default Colormap for Matplotlib | SciPy 2015 | Nathaniel Smith and SteĢfan van der Walt](https://www.youtube.com/watch?v=xAoljeRJ3lU)
- blog post for above video: <https://bids.github.io/colormap/>
- [Origins of Colormaps, Cleve Moler, February 2, 2015](https://blogs.mathworks.com/cleve/2015/02/02/origins-of-colormaps/)
- [Documenting the matplotlib colormaps, @endolith](https://gist.github.com/endolith/2719900)
- [Color Map Advice for Scientific Visualization](https://www.kennethmoreland.com/color-advice/)
- <https://colorcet.com/>, Peter Kovesi
- [Kovesi: Good Colour Maps: How to Design Them.](https://arxiv.org/abs/1509.03700)
- <https://www.fabiocrameri.ch/colourmaps/>

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cmap",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Talley Lambert <talley.lambert@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/1f/16/370c001169f5ae53fa351bada30f34375e6a0b205bc23da0aaf4a1306ef4/cmap-0.2.0.tar.gz",
    "platform": null,
    "description": "# cmap\n\n[![License](https://img.shields.io/pypi/l/cmap.svg?color=green)](https://github.com/tlambert03/cmap/raw/main/LICENSE)\n[![PyPI](https://img.shields.io/pypi/v/cmap.svg?color=green)](https://pypi.org/project/cmap)\n![Conda](https://img.shields.io/conda/v/conda-forge/cmap)\n[![Python Version](https://img.shields.io/pypi/pyversions/cmap.svg?color=green)](https://python.org)\n[![CI](https://github.com/tlambert03/cmap/actions/workflows/ci.yml/badge.svg)](https://github.com/tlambert03/cmap/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/tlambert03/cmap/branch/main/graph/badge.svg)](https://codecov.io/gh/tlambert03/cmap)\n[![Documentation Status](https://readthedocs.org/projects/cmap-docs/badge/?version=latest)](https://cmap-docs.readthedocs.io/en/latest/?badge=latest)\n\nScientific colormaps for python, with no dependencies beyond numpy.\n\nWith `cmap`, you can use any of the colormaps from\n[matplotlib](https://matplotlib.org/stable/tutorials/colors/colormaps.html),\n[cmocean](https://matplotlib.org/cmocean/),\n[colorbrewer](https://colorbrewer2.org/),\n[crameri](https://www.fabiocrameri.ch/colourmaps/),\n[seaborn](https://seaborn.pydata.org/tutorial/color_palettes.html), and a host\nof other collections in your python code, without having to install matplotlib\nor any other dependencies beyond numpy.\n\n:book: [See the complete\ncatalog](https://cmap-docs.readthedocs.io/en/latest/catalog/)\n\nThere are a number of python libraries that provide or require colormaps or\nbasic color support, but they all either depend on matplotlib, provide a\nspecialized set of colormaps intended to extend those provided by matplotlib, or\nroll their own colormap solution that vendors/duplicates other libraries.\n\n`cmap` is a lightweight, library that provides a large collection of colormaps\nwith no dependencies beyond numpy.  It provides exports to a number of known\nthird-party colormap objects, allowing it to be used across a wide range of\npython visualization libraries.  The intention is to provide a library that can\nbe used by any python library that needs colormaps, without forcing the user to\ninstall matplotlib (while still being compatible with matplotlib and other\nlibraries that use matplotlib colormaps).\n\n`cmap` is strictly typed and fully tested, with a focus on good developer\nexperience.\n\n## Install\n\n```\npip install cmap\n```\n\n```\nconda install -c conda-forge cmap\n```\n\n## Usage\n\nSee [Documentation](https://cmap-docs.readthedocs.io/) for full details.\n\n### [`cmap.Color`](https://cmap-docs.readthedocs.io/en/latest/colors/)\n\nThe `cmap.Color` object is a simple wrapper around a tuple of RGBA scalars, with\na few convenience methods for converting to other color objects.\n\n```python\nfrom cmap import Color\n\nred = Color(\"red\")  # or a variety of other \"color like\" inputs\n```\n\n### [`cmap.Colormap`](https://cmap-docs.readthedocs.io/en/latest/colormaps/)\n\nThe `cmap.Colormap` object is a callable that can map a scalar value (or numpy\narray of values) to an RGBA color (or a numpy array of RGBA colors).  API is\nintended to mimic the behavior of a\n[`matplotlib.colors.Colormap`](https://matplotlib.org/stable/api/_as_gen/matplotlib.colors.Colormap.html#matplotlib.colors.Colormap)\nobject (without requiring matplotlib)\n\n```python\nIn [1]: import cmap\n\n# or a variety of other \"colormap like\" inputs\nIn [2]: cmap1 = cmap.Colormap([\"red\", \"green\", \"blue\"])\n\nIn [3]: cmap1(np.linspace(0,1,5))\nOut[3]:\narray([[1.        , 0.        , 0.        , 1.        ],\n       [0.50393701, 0.24900417, 0.        , 1.        ],\n       [0.        , 0.50196078, 0.        , 1.        ],\n       [0.        , 0.24900417, 0.50393701, 1.        ],\n       [0.        , 0.        , 1.        , 1.        ]])\n```\n\nNote that the input array must be normalized from 0-1, so if you're applying a colormap\nto an integer array (like an image) you must apply any contrast limits and rescale to\n0-1 before passing it to a `Colormap`.\n\n## Third Party Library Support\n\nThe `cmap.Colormap` object has convenience methods that export it to a number of known\nthird-party colormap objects, including:\n\n- [matplotlib](https://matplotlib.org/)\n- [napari](https://napari.org/)\n- [vispy](https://vispy.org/)\n- [pygfx](https://pygfx.readthedocs.io/en/latest/) (& [fastplotlib](https://github.com/fastplotlib/fastplotlib))\n- [plotly](https://plotly.com/python/)\n- [bokeh](https://docs.bokeh.org/en/latest/)\n- [altair](https://altair-viz.github.io/)\n- [pyqtgraph](https://www.pyqtgraph.org/)\n\nSee [documentation](https://cmap-docs.readthedocs.io/en/latest/colormaps/#usage-with-external-visualization-libraries)\nfor details.\n\nIf you would like to see support added for a particular library, please open an issue or PR.\n\n## Alternatives\n\nOther libraries providing colormaps:\n\n- [matplotlib](https://matplotlib.org/stable/tutorials/colors/colormaps.html)\n- [seaborn](https://seaborn.pydata.org/tutorial/color_palettes.html)  (subclasses matplotlib)\n- [proplot](https://proplot.readthedocs.io/en/latest/colormaps.html)  (subclasses matplotlib)\n- [palettable](https://jiffyclub.github.io/palettable/) (mostly data, import doesn't depend on matplotlib, but usage largely does)\n- [cmocean](https://matplotlib.org/cmocean/) (mostly data, outputs matplotlib colormaps)\n- [colorcet](https://colorcet.holoviz.org/) (mostly data, usage requires either matplotlib or bokeh)\n- [cmasher](https://cmasher.readthedocs.io/) (requires matplotlib)\n- [cmyt](https://github.com/yt-project/cmyt) (requires matplotlib)\n- [cmcrameri](https://github.com/callumrollo/cmcrameri) (requires matplotlib, wraps <https://www.fabiocrameri.ch/colourmaps/>)\n- [distinctipy](https://github.com/alan-turing-institute/distinctipy)  (generates distinct color sets, only requires numpy)\n- [Farrow & Ball Matplotlib](https://github.com/vork/farrowandball) (requires matplotlib)\n- [mplcyberpunk](https://github.com/dhaitz/mplcyberpunk) (requires matplotlib)\n\n## References and Further reading\n\n- [Choosing Colormaps in Matplotlib](https://matplotlib.org/stable/tutorials/colors/colormaps.html)\n- [A Better Default Colormap for Matplotlib | SciPy 2015 | Nathaniel Smith and Ste\u0301fan van der Walt](https://www.youtube.com/watch?v=xAoljeRJ3lU)\n- blog post for above video: <https://bids.github.io/colormap/>\n- [Origins of Colormaps, Cleve Moler, February 2, 2015](https://blogs.mathworks.com/cleve/2015/02/02/origins-of-colormaps/)\n- [Documenting the matplotlib colormaps, @endolith](https://gist.github.com/endolith/2719900)\n- [Color Map Advice for Scientific Visualization](https://www.kennethmoreland.com/color-advice/)\n- <https://colorcet.com/>, Peter Kovesi\n- [Kovesi: Good Colour Maps: How to Design Them.](https://arxiv.org/abs/1509.03700)\n- <https://www.fabiocrameri.ch/colourmaps/>\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License",
    "summary": "Scientific colormaps for python, without dependencies",
    "version": "0.2.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/tlambert03/cmap/issues",
        "Documentation": "https://cmap-docs.rtfd.io/",
        "Homepage": "https://github.com/tlambert03/cmap",
        "Repository": "https://github.com/tlambert03/cmap"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7763000b6446b27e3cc9ce55a3b8aeafc1a0995269be43883113af865611fe11",
                "md5": "3452b9fda80a43afab5fb5b2d0fe3593",
                "sha256": "dd825491c3d95b75bac0aeb1964f9b3e3c1ef935799e016938829f0cd7e7e3f1"
            },
            "downloads": -1,
            "filename": "cmap-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3452b9fda80a43afab5fb5b2d0fe3593",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 621767,
            "upload_time": "2024-04-28T18:22:19",
            "upload_time_iso_8601": "2024-04-28T18:22:19.677604Z",
            "url": "https://files.pythonhosted.org/packages/77/63/000b6446b27e3cc9ce55a3b8aeafc1a0995269be43883113af865611fe11/cmap-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1f16370c001169f5ae53fa351bada30f34375e6a0b205bc23da0aaf4a1306ef4",
                "md5": "8403e7e2142ebe7b6a479928862531c4",
                "sha256": "02c01eb0e196932e8cbcece8f1cff7e1126842356a7ea190f6810e9ad8f2af35"
            },
            "downloads": -1,
            "filename": "cmap-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8403e7e2142ebe7b6a479928862531c4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 579649,
            "upload_time": "2024-04-28T18:22:22",
            "upload_time_iso_8601": "2024-04-28T18:22:22.082689Z",
            "url": "https://files.pythonhosted.org/packages/1f/16/370c001169f5ae53fa351bada30f34375e6a0b205bc23da0aaf4a1306ef4/cmap-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-28 18:22:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tlambert03",
    "github_project": "cmap",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cmap"
}
        
Elapsed time: 0.22773s