Giter Site home page Giter Site logo

secretcolors's Introduction

SecretColors

PyPI version Documentation Status

Library generated for making plots with better color palette. It uses famous color palettes and adds few helpful functions.

Currently it supports following Color Palettes

  • IBM Color Palette (ibm)
  • Google Material Design Color Palette (material)
  • Google Material Design Accent Color Palette (material-accent)
  • ColorBrewer2 Color Palette (brewer)
  • VMWare Clarity Color Palette (clarity)
  • Tableau Color Palette (tableau)

You can get output of colors in variety of color formats including hex , rgb, rgba etc.

See changelog to know what's new!

Few sample plots and inspiration behind this library can be found in WeirdData blog.

Default base colors in matplotlib and SecretColors palettes.
Simple bar plot with default colors.
Histogram comparison with Magenta and Cyan. You can dramatically change colors by just passing single parameter.

Installation

pip install SecretColors

Documentation

Full documentation and API reference can be accessed via ReadTheDocs

SecretColors is a very flexible library. You can easily select different color palettes.

from SecretColors import Palette

p = Palette()  # Generates Default color palette i.e. IBM Color Palette
ibm = Palette("ibm")  # Generates IBM Palette
ibm.red()  # Returns '#fb4b53'
material = Palette("material")  # Generates Material Palette
material.red()  # Returns '#f44336'

Select different types of color modes

p1 = Palette() # Default Color mode (hex)
p1.green() # '#24a148'
p2 = Palette(color_mode="hexa")
p2.green() # '#24a148ff'
p3 = Palette(color_mode="ahex")
p3.green() # '#ff24a148'
p4 = Palette(color_mode="rgb")
p4.green() # (0.141, 0.631, 0.282)
p5 = Palette(color_mode="rgba")
p5.green() # '(0.141, 0.282, 0.631, 1)'

Note: matplotlib can accepts hex, rgb or hexa

Get random colors

p = Palette()
p.random() # '#90dbe9'
p.random(no_of_colors=3) # ['#8fca39', '#64a0fe', '#7430b6']
p.random(no_of_colors=2, shade=20) # ['#b3e6ff', '#c2dbf4']

Unlimited color manipulations

p = Palette()
p.blue()  # normal blue [#408bfc]
p.blue(shade=20)  # lighter shade of blue [#c9deff]
p.blue(shade=70)  # darker shade of blue [#054ada]
p.blue(shade=16.10)  # arbitrary shade of blue (between 0 to 100) [#dbe9ff]
p.blue(no_of_colors=3)  # Three blue shades ['#b8d4ff', '#408bfc', '#0546d4']
p.blue(no_of_colors=3, starting_shade=30)  # Three blue shades with lightest one is 30 ['#64a0fe', '#005ef9', '#052ea8']
p.blue(no_of_colors=3, ending_shade=40)  # Three blue shades with darkest one is 40 ['#edf4ff', '#c9deff', '#97c1ff']
p.blue(no_of_colors=3, starting_shade=30, ending_shade=40) # Three blue shades with lightest 30 and darkest 60 ['#8cbaff', '#8cbaff', '#8cbaff']
p.blue(no_of_colors=3, gradient=False) # Three blue shades in random order ['#8cbaff', '#b8d4ff', '#64a0fe']
p.color_mode = "rgba"
p.blue(alpha=0.3) # Blue with alpha (0.251, 0.988, 0.545, 0.3) Only works in color mode which outputs alpha values

Flexible functions

get_complementary("#24a148") # Get complementary color [#a0237c]
hex_to_rgb("#a0237c") # (0.627, 0.137, 0.486)
hex_to_hsl("#a0237c") # (0.881, 0.641, 0.382)
hex_to_hex_a("#a0237c", alpha=0.7) # Get hex with transparency at end [#a0237cb2]
hex_to_ahex("#a0237c", alpha=0.7) # Get hex with transparency at start [#b2a0237c]
color_in_between("#24a148","#a0237c") # Color between two ['#616161']
color_in_between("#24a148","#a0237c", steps=4) # 3 colors between two ['#428154', '#616161', '#80426e'] such that color space is divided into 4 parts
rgb_to_hex(0.181, 0.241, 0.382) # '#2e3d61'
rgb_to_hsl(0.181, 0.241, 0.382) # (0.617, 0.357, 0.281)
hsl_to_hex(0.181, 0.241, 0.382) # '#747849'

Custom and flexible colormaps which can be directly used in matplotlib workflow

import matplotlib
import matplotlib.pylab as plt
import numpy as np
from SecretColors.cmaps import ColorMap
from SecretColors import Palette
p = Palette()
c = ColorMap(matplotlib, p)
data = np.random.rand(100, 100)
plt.pcolor(data, cmap=c.greens())
plt.show()

Create your own colormaps or make it qualitative colormap

color_list = [p.red(), p.blue()]
plt.pcolor(data, cmap=c.from_list(color_list, is_qualitative=True))
plt.show()

Reverse the direction

plt.pcolor(data, cmap=c.greens(is_reversed=True))

TODO

  • CIE XYZ to CIE Lab conversions
  • Color Palettes - Latitude, Polaris, Adobe Spectrum
  • Direct support for more RGB to XYZ conversions
  • Generate Color Palette from image
  • Color blind safe palette
  • Out of the box LinearSegmentedColormap object

We can not implement 'out of the box' colormaps for matplotlib because matplotlib checks its type before its use. Hence we can not make new class which can be directly act as a substitute.

Note: All CIE-XYZ conversion and colorblind simulation functions are still in beta-testing. Do not use them in your production code

Contribution and Feedback

Feel free to provide feedback and criticism through GitHub or you can email me [email protected] . If you want to contribute, please send pull request to this repository.

Acknowledgments

Colors used in this library are partly taken from IBM Design Language , Google Material Design , ColorBrewer, VMWare Clarity and Tableau .

Color name data is taken from X11 and W3.

RGB colorspace matrices were taken from Here .

Any other specific code or resource used in this library is attributed in respective function or method where it is used. It can be accessible from our online documentation as well.

License

This library and its code is released under MIT License . Read full statement here.

secretcolors's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

secretcolors's Issues

Issue while accessing get_colors in ColorMaps

Issue while accessing get_colors in ColorMaps

/opt/anaconda3/envs/analysis/lib/python3.9/site-packages/SecretColors/cmaps/parent.py in get_colors(self, name, no_of_colors)
    244                 self.log.error(f"Currently following number of colors are "
    245                                f"allowed for {name}. : {n}")
--> 246             return self.data[name][no_of_colors]
    247         return []
    248 

Picking random colors can result in an IndexError

What i am trying to do

I am trying to pick a random color via SecretColors.Palette(palette_name, show_warning=False).random()

What i expect to happen

A random color should be returned, most of the time, it does correctly do that.

What happens instead

Apparently - very rarely - this happens:

  File "/home/riot/src/isomer/isomer_master/isomer/misc/__init__.py", line 906, in std_color
    color = SecretColors.Palette(palette_name, show_warning=False).random()
  File "/home/riot/.virtualenvs/isomer/lib/python3.7/site-packages/SecretColors/palette.py", line 368, in random
    force_gray=force_gray), alpha=alpha,
  File "/home/riot/.virtualenvs/isomer/lib/python3.7/site-packages/SecretColors/palette.py", line 297, in __random
    ending_shade=end_shade)
  File "/home/riot/.virtualenvs/isomer/lib/python3.7/site-packages/SecretColors/palette.py", line 274, in __random_pick
    no_of_colors)
  File "/home/riot/.virtualenvs/isomer/lib/python3.7/site-packages/SecretColors/__color.py", line 206, in random_between
    return [self.shade(x) for x in random_shades]
  File "/home/riot/.virtualenvs/isomer/lib/python3.7/site-packages/SecretColors/__color.py", line 206, in <listcomp>
    return [self.shade(x) for x in random_shades]
  File "/home/riot/.virtualenvs/isomer/lib/python3.7/site-packages/SecretColors/__color.py", line 186, in shade
    return col2[ind2]
IndexError: list index out of range

Steps to Reproduce

import SecretColors as sc

for x in range(10000):
    _ = sc.Palette().random()

numpy dependency is a bit too new, maybe

I'm having trouble installing SecretColors as dependency on Debian stable (buster) systems, as these only have python3-numpy 1.16.

Luckily (i tested) SecretColors doesn't even need that new of a numpy, so i propose downgrading it to >=1.16.2

Edit: Also, currently newer versions than 1.19.1 are rejected, which would be the case on any newer-than-stable Debian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.