A package for storing and visualizing palettes, and constructing new ones via polynomial interpolation and image extraction. Now pippable!
*This package borrows inspiration from @jmaasch's scatterplots in her package [`sanzo`](https://github.com/jmaasch/sanzo), and uses extraction algorithms from @qTipTip's package [`Pylette`](https://github.com/qTipTip/Pylette).*
frieda | plath | selah | blonde | honeycombe |
crepuscule | leather | gucci | sandbar | fiestaware |
chilaquiles | eleven | splenda | gremlin | pollen |
medium | juniper | polya | ostrich | fraiche |
cheshire | carmine | joan* | pinot | addams |
minuit | fugazi | clementine | leda | pugsley |
bellhooks | wes | lysergic | pepo | reese |
lufte | oolong | pitaya | alice | neko |
belle | spiff | yoshi | phoebe | pam |
menthol | dwight | riley | mona | eeyore |
rory | pudding | marmalade | polaris | trefoil |
harmon | abed | shirley | surely | annie |
pierce | britta | strogatz | lutz | writhe |
perl* | roosh | seafare | heliotrope | moonbow |
peanuts | naval | indomie | maggie | rainbow |
??? | quinone | quinoline | diverging | orb* |
warble* | waitomo* | vylette* | pom* | lava* |
pumpkin* | pinctada* | nacre* | moxxi* | salvia* |
bluefish | BuPu* | holst | joker* | rach* |
blink* | betan* | rue* | otterpop* | gummi* |
emporium | paired | category20a | category20b | category20c |
* available as xxx256
[discrete] [monochrome continuous] [polychromatic continuous] [bokeh]
Visualizations include swatches, pies, points, lines, scatters. Somewhat helpful for seeing how colors behave on a plot, in dense or scattered visuals. Sometimes colors look great together on a swatch, but not so great in their pointillistic forms.
palette
: list or iterable any combination of hex strings or rgb tuples or HTMLbg_color
: HTML or hex string background fill coloralpha
: fraction between 0.0 and 1.0 alpha transparency of entire paletteshuffle
: boolean shuffles palette
Testing out panel's new colorpicker widget! Useful for adjusting palettes to personal taste.
n
: list or integer
Given palette and 1D quantitative axis, returns list of mapped colors. Uses min and max to first and last of palette
q
: 1D quantitative axis, numpy arraypalette
: color palette to map to- Returns
colors
: list of mapped colors
Given palette and 1D quantitative axis, returns list of mapped colors. Instead of min and max of dataset, uses customized end points.
For example, a dataset may range from (-1, 1), and you want extreme colors to reflect those bounds, not necessarily your dataset's range.
q
: 1D quantitative axis, numpy arraypalette
: color palette to map toq_min_thresh
: minimum threshold, default -infinityq_max_thresh
: maximum threshold, default +infinitymin_color
: color to map minimum threshold to (otherwise set to first color in palette)max_color
: color to map maximum threshold to (otherwise set to last color in palette)nan_color
: color to map nan values to- Returns
colors
: list of mapped colors
For customizing diverging palettes with variable breakpoints and thresholds.
For example, a dataset may range from (-x, +y), and you want zero to be the color/point at which the colors diverge.
This function assumes you pass in a balanced palette, but 'midpoint' can approximately adjust this.
q
: 1D quantitative axis, numpy arraypalette
: color palette to map toq_dividing
: dividing numeric value corresponding to divergence in paletteq_min_thresh
: minimum threshold, default -infinityq_max_thresh
: maximum threshold, default -infinitynan_color
: color to map nan values to, default blackmidpoint
: fraction, where to set midpoint of colorbar to, default 0.5- Returns
colors
: list of mapped colors
palpolate
(pal-(ette inter)-polate):
input lists of any size and user can control output size.
There are a multitude of beautiful gradients in packages like bokeh and colorcet that are, for the most part, static. The interpolation scheme here can be used to create entirely new ones given only a few endpoints. This part is still in development, but currently uses linear or polynomial fits in color space metrics RGB, HSL, or HSV. Heatmaps are a good way to visualize the results!
On the left are the input palettes, and on the right are the output palettes all approximately of size 256.
palette
: list or iterable any combination of hex strings or rgb tuples or HTMLn_colors
: integer approximate desired length of final palettemethod
: string 'rgb' or 'hsv' or 'hsl' interpolation metric, default 'rgb'curve
: boolean if True, fit t 2ndº polynomial if False, simple linear interpolationdirections
: list of 3 strings, 'up' or 'down' each entry corresponds to r, g, b 'up' pushes intermediate values higher (lighter) 'down' pushes intermediate values lower (darker)
Extract palette of size n_colors
from image given image path using k-means or median cut algorithms.
path
: string of image pathn_colors
: integer number of colors to extractmethod
: 'kmeans' or 'median' or 'both' algorithm of extraction either k-means clustering or median cut, default k-meansresize
: boolean, default True resizing samples a smaller image, speeds up extractionsort
: boolean, default False amateur sort by luminanceshow
: boolean, default True prints palette and returns panel object
Palettes can be retrieved from command line:
>>> chromatose leda
>>> ['#2c2f30', '#8fa7d7', '#afd7d6', '#aa3731', '#f5b3b8']
Palettes can be extracted from command line:
>>> extract egg.png
>>> K-Means: ['#050002', '#0c1c7b', '#013adc', '#1b143a', '#294254']
>>> Median Cut: ['#040000', '#080006', '#1e1b3c', '#1e2d61', '#0330bd']
Palette extraction from image path using both k-means and median cut
algorithms. Defaults to 5 colors, resized, unsorted, and not displayed.
path path to image
-n , --ncolors length of palette (int, default 5)
-r , --resize resize for efficiency (bool, default True)
-s , --show display pillow swatches (bool, default False)
frieda
plath
selah
blonde
honeycombe
lysergic
pepo
reese
rainbow
lufte
pitaya
spiff
leather
medium
addams
mona
leda
rory
pudding
polaris
trefoil
writhe
perl*
roosh
heliotrope
indomie
strogatz
juniper
quinone
minuit
alice
wes
pam
dwight
marmalade
harmon
shirley
annie
pierce
britta
abed
eeyore
neko
maggie
quinoline
peanuts
eleven
naval
fugazi
clementine
diverging
lutz
moonbow
chilaquiles
fiestaware
polya
splenda
pollen
fraiche
cheshire
bellhooks
belle
phoebe
ostrich
yoshi
salvia*
pom*
lava*
moxxi*
joan*
waitomo*
warble*
vylette*
pumpkin*
crest*
nacre*
salvia256
warble256
waitomo256
vylette256
pom256
moxxi256
lava256
pumpkin256
joan256
nacre256
crest256
joker*
rach*
orb*
blink*
rue*
betan*
bluefish
otterpop*
gummi*
emporium*
perl256
orb256
blink256
otterpop256
gummi256
emporium256
betan256
rue256
rach256
joker256
paired
category20a
category20b
category20c
"The last color she remembered was the indigo chips in the headstone. After that she became as color conscious as a hen."