Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nens/colormaps
Fast and easy discrete and continuous colormaps.
https://github.com/nens/colormaps
Last synced: 4 days ago
JSON representation
Fast and easy discrete and continuous colormaps.
- Host: GitHub
- URL: https://github.com/nens/colormaps
- Owner: nens
- License: mit
- Created: 2014-04-03T09:35:41.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-09-09T08:29:22.000Z (about 2 years ago)
- Last Synced: 2024-04-12T01:12:28.438Z (7 months ago)
- Language: Python
- Size: 216 KB
- Stars: 0
- Watchers: 34
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE.rst
Awesome Lists containing this project
README
colormaps
=========Introduction
------------Transform data into rgba data using discrete lookup tables or color
gradients.Usage
-----Create a discrete colormap with the same two colors::
>>> import colormaps
>>> colormap = colormaps.DiscreteColormap(
... data=[(0, (255, 0, 0, 255)),
... (1, (0, 0, 255, 127))],
... masked=(255, 0, 0, 255),
... invalid=(0, 255, 0, 255),
... )Create a gradient colormap from red to semi-transparent blue::
>>> import colormaps
>>> colormap = colormaps.GradientColormap(
... data=[(0, (255, 0, 0, 255)),
... (1, ( 0, 0, 255, 127))],
... size=2048,
... masked=(0, 0, 255, 255),
... )Where size is the amount of entries in the prepared look-up table.
Calculate the value at some positions::
>>> colormap([0, 0.5, 1])
array([[255, 0, 0, 255],
[127, 0, 127, 190],
[ 0, 0, 255, 127]], dtype=uint8)Register the colormap for use in other places::
>>> colormap.register('my_gradient')
>>> colormaps.get('my_gradient')
Use a collection of predefined colors using a manager::
>>> manager = colormaps.Manager()
>>> manager.get('jet')
>>> sorted(manager.registered.keys())[:3]
['Accent', 'Accent_r', 'Blues']Or use your own collection::
>>> manager = colormaps.Manager('path/to/my/colormap/collection')
The path should point to a folder with json-files ('my-colormap.json')
containing the kwargs for colormaps.create() like this::{
"type": "GradientColormap",
"data": [
[0.000, [ 0, 0, 0, 255]],
[0.700, [255, 255, 255, 0]],
[1.000, [255, 255, 255, 255]]
]
}Development installation
------------------------For development, you can use a docker-compose setup::
$ docker-compose build --build-arg uid=`id -u` --build-arg gid=`id -g` lib
$ docker-compose up --no-start
$ docker-compose start
$ docker-compose exec lib bashCreate a virtualenv::
(docker)$ virtualenv .venv # note that Dockerfile prepends .venv/bin to $PATH
Install stuff and run the tests::
(docker)$ pip install -r requirements.txt
(docker)$ pip install -e .[test]
(docker)$ pytestUpdate packages::
(docker)$ rm -rf .venv
(docker)$ virtualenv .venv
(docker)$ pip install -e .
(docker)$ pip freeze | grep -v colormaps > requirements.txt