Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (6.8%) to scientific vocabulary
Repository
Easy color scales and color conversion for Python.
Basic Info
- Host: GitHub
- Owner: jsvine
- License: mit
- Language: Python
- Default Branch: master
- Homepage: http://nbviewer.ipython.org/github/jsvine/spectra/blob/master/docs/walkthrough.ipynb
- Size: 52.7 KB
Statistics
- Stars: 261
- Watchers: 8
- Forks: 9
- Open Issues: 7
- Releases: 1
Metadata Files
README.md
Spectra
Spectra is a Python library that makes color math, color scales, and color-space conversion easy. Support for:
- Color scales
- Color ranges
- Color blending
- Brightening/darkening colors
- Saturating/desaturating colors
- Conversion to/from multiple color spaces
Spectra is built on colormath2 and grapefruit. Spectra is enormously inspired by chroma.js and d3's scales.
Installation
sh
pip install spectra
Walkthrough
See this walkthrough to see what Spectra can do.
API
Creating color objects from web-colors or hexcode strings
spectra.html(html_string)
E.g., spectra.html("papayawhip"), spectra.html("#BAABAA") spectra.html("#FFF")
Creating color objects from color space values
spectra.rgb(r, g, b)
Specifically: sRGB
spectra.lab(L, a, b)
Specifically: CIELAB
spectra.lch(L, c, h)
Also known elsewhere as "hcl"
spectra.hsl(h, s, l)
spectra.hsv(h, s, v)
spectra.xyz(x, y, z)
spectra.cmy(c, m, y)
spectra.cmky(c, m, y, k)
Getting color values
Instances of spectra.Color have four main properties:
.values: An array representation of the color's values in its own color space, e.g.(L, a, b)for anlabcolor..hexcode: The hex encoding of this color, e.g.#ffffffforrgb(255, 255, 255)/html(\"white\")..rgb: The(r, g, b)values for this color in thergbcolor space; these are allowed to go out of gamut..clamped_rgb: The \"clamped\"(r, g, b)values for this color in thergbcolor space.
Note on .rgb and .rgb_clamped: Spectra follows colormath's convention:
RGB spaces tend to have a smaller gamut than some of the CIE color spaces. When converting to RGB, this can cause some of the coordinates to end up being out of the acceptable range (0.0-1.0 or 1-255, depending on whether your RGB color is upscaled). [...] Rather than clamp these for you, we leave them as-is.
Modifying colors
color.to(space)
Convert this color to another color space.
```python teallab = spectra.html("teal").to("lab") print(teallab.values)
(48.25453959565715, -28.843707890081394, -8.48135382506432) ```
color.blend(other_color, ratio=0.5)
Blend this color with another color, using ratio of that other color.
```python yellow, red = spectra.html("red"), spectra.html("yellow") orange = yellow.blend(red) print(orange.hexcode)
'#ff8000' ```
color.brighten(amount=10)
Brighten this color by amount luminance. (Converts this color to the LCH color space, and then increases the L parameter by amount.)
```python teal = spectra.html("teal") lightteal = lightteal.brighten(30) print(light_teal.hexcode)
'#75d1d0' ```
color.darken(amount=10)
The opposite of color.brighten; reduces color by amount luminance.
color.saturate(amount=10)
Saturate this color by amount chroma. (Converts this color to the LCH color space, and then increases the C parameter by amount.)
color.desaturate(amount=10)
The opposite of color.saturate; reduces color by amount chroma.
Creating color scales
spectra.scale(colors)
colors should be a list of two or more colors (created by any of the methods above), web-color names, or hexcodes.
Returns a spectra.Scale object, which translates numbers to their corresponding colors:
```python myscale = spectra.scale([ "gray", "red" ]) halfway = myscale(0.5) print(halfway.hexcode)
'#c04040' ```
Modifying color scales
scale.domain(numbers)
By default, a scale's domain is [ 0, 1 ]. But you can change it to be anything else, e.g.:
```python myscale = spectra.scale([ "gray", "red" ]).domain([ 10, 20 ]) halfway = myscale(15) print(halfway.hexcode)
'#c04040' ```
Creating color ranges
scale.range(count)
This function returns a list of spectra.Color objects evenly spaced between a scale's colors. For example:
```python myscale = spectra.scale([ "gray", "red" ]) myrange = my_scale.range(5)
print(my_range)
[
, , , , ]
print([ c.hexcode for c in my_range ])
['#808080', '#a06060', '#c04040', '#df2020', '#ff0000'] ```
Alternatively, as a shortcut, you can use spectra.range(colors, count).
Feedback/Suggestions
Issues and pull requests very much appreciated.
Owner
- Name: Jeremy Singer-Vine
- Login: jsvine
- Kind: user
- Website: jsvine.com
- Repositories: 78
- Profile: https://github.com/jsvine
Liberating data @ data-liberation-project.org, newslettering @ data-is-plural.com
GitHub Events
Total
- Create event: 1
- Release event: 1
- Issues event: 6
- Watch event: 6
- Issue comment event: 11
- Push event: 3
- Pull request event: 6
- Fork event: 2
Last Year
- Create event: 1
- Release event: 1
- Issues event: 6
- Watch event: 6
- Issue comment event: 11
- Push event: 3
- Pull request event: 6
- Fork event: 2
Committers
Last synced: about 1 year ago
Top Committers
| Name | Commits | |
|---|---|---|
| Jeremy Singer-Vine | j****e@g****m | 29 |
| Robert Smallshire | r****t@s****k | 2 |
| Tim Gates | t****s@i****m | 1 |
| Phil Ewels | p****s@s****e | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 19
- Total pull requests: 9
- Average time to close issues: about 1 month
- Average time to close pull requests: 6 days
- Total issue authors: 16
- Total pull request authors: 5
- Average comments per issue: 2.26
- Average comments per pull request: 0.89
- Merged pull requests: 7
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 3
- Pull requests: 6
- Average time to close issues: 10 days
- Average time to close pull requests: 6 days
- Issue authors: 2
- Pull request authors: 2
- Average comments per issue: 2.33
- Average comments per pull request: 1.0
- Merged pull requests: 4
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- rob-smallshire (2)
- jsvine (2)
- gfairchild (2)
- cameron-finn (1)
- pojoba02 (1)
- PalmDr (1)
- earthbound19 (1)
- araichev (1)
- emlyn (1)
- abingham (1)
- briantjacobs (1)
- mazznoer (1)
- AI-ML-Enthusiast (1)
- connorferster (1)
- tony (1)
Pull Request Authors
- rob-smallshire (4)
- apraga (2)
- timgates42 (1)
- ewels (1)
- jsvine (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 2
-
Total downloads:
- pypi 28,422 last-month
- Total docker downloads: 87,084
-
Total dependent packages: 6
(may contain duplicates) -
Total dependent repositories: 92
(may contain duplicates) - Total versions: 16
- Total maintainers: 1
pypi.org: spectra
Color scales and color conversion made easy for Python.
- Homepage: http://github.com/jsvine/spectra
- Documentation: https://spectra.readthedocs.io/
- License: MIT
-
Latest release: 0.1.0
published over 1 year ago
Rankings
Maintainers (1)
conda-forge.org: spectra
Spectra is a Python library that makes color math, color scales, and color-space conversion easy. It has support for Color scales, Color ranges, Color blending, Brightening/darkening colors, Saturating/desaturating colors and Conversion to/from multiple color spaces. Spectra is built on colormath and grapefruit. Spectra is enormously inspired by chroma.js and d3's scales.
- Homepage: http://github.com/jsvine/spectra
- License: MIT
-
Latest release: 0.0.11
published almost 4 years ago
Rankings
Dependencies
- colormath >=3.0.0