Skip to content

Instantly share code, notes, and snippets.

@konverner
Created January 8, 2023 15:32
Show Gist options
  • Save konverner/0cc0659a516252f1b6465d53c18f9ece to your computer and use it in GitHub Desktop.
Save konverner/0cc0659a516252f1b6465d53c18f9ece to your computer and use it in GitHub Desktop.
it creates a color gradient of two colors, i.e. a list of hex-color strings from c1 to c2
import numpy as np
import matplotlib
def colorGrdient(c1: str, c2: str, n: int):
"""
c1 : color FROM (e.g. '#FFCDD2')
c2 : color TO (e.g. '#BBDEFB')
"""
c1=np.array(matplotlib.colors.to_rgb(c1))
c2=np.array(matplotlib.colors.to_rgb(c2))
return [matplotlib.colors.to_hex((1-(i/n))*c1 + (i/n)*c2) for i in range(n)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment