Gradpyent, a Python Gradient Generator
Gradpyent is a Python package for generating color gradients based on list-like inputs and start/end color values. The generated gradients are ideal for data visualization, user interfaces, or anywhere you want to convert a list of values into a color gradient.
This package allows you to specify colors in a variety of formats including RGB, HTML, and KML, giving you the flexibility to match your specific needs.
The gradient generation algorithm automatically scales input values outside the range of 0-1, ensuring the generated gradient remains consistent and visually pleasing.
Table of Contents
Installation
You can install Gradpyent directly from PyPI:
pip install gradpyent
Usage
Basic usage:
from gradpyent.gradient import Gradient
start_color = 'RGB(255,0,0)'
end_color = '#0000ff'
gg = Gradient(gradient_start=start_color, gradient_end=end_color, opacity=1.0)
input_list = [0, 0.5, 1]
gradient = gg.get_gradient_series(series=input_list, fmt='html')
print(gradient)
Examples
Here are some more examples demonstrating how to use different color formats and list inputs:
start_color = 'rgb(255,0,0)'
end_color = 'rgb(0,0,255)'
input_list = [0, 0.5, 1]
start_color = '#ff0000'
end_color = '#0000ff'
input_list = [0, 0.5, 1]
start_color = 'ff0000ff'
end_color = 'ffff0000'
input_list = [0, 0.5, 1]
start_color = 'rgb(255,0,0)'
end_color = '#0000ff'
input_list = [-5, 0, 5, 10]
- Jupyter notebook samples:
- See the
notebooks
directory for more examples
License
This project is licensed under the terms of the MIT license. See the LICENSE.md file for details.
Code Quality
ruff format src/ tests/
ruff check src/ [--fix]
Tests
pytest --cov
Docs
sphinx-apidoc -o docs/ src/gradpyent
Enjoy the colorful world!