Skip to content

Instantly share code, notes, and snippets.

@andrewmoles2
Last active April 1, 2025 09:27
Show Gist options
  • Save andrewmoles2/67fbd05bae17499f77a5682d5cffc40f to your computer and use it in GitHub Desktop.
Save andrewmoles2/67fbd05bae17499f77a5682d5cffc40f to your computer and use it in GitHub Desktop.
Coolors function in Python
# import plotnine for demo and testing
from plotnine import *
from plotnine.data import mtcars
def coolors(URL):
URL = URL.rsplit("/", 1)[-1].replace("-", ",").split(",")
hex_codes = ["#" + hex for hex in URL]
return hex_codes
# test
url = str("https://coolors.co/00a878-6ccd8c-d8f1a0-e6d98c-f3c178-f9905d-fe5e41-853221-0b0500")
url2 = str("https://coolors.co/palette/f4f1de-e07a5f-3d405b-81b29a-f2cc8f")
print(coolors(url))
print(coolors(url2))
test_plot = ggplot(mtcars, aes('mpg', 'hp', color = 'factor(carb)')) +\
geom_point() +\
scale_color_manual(values = coolors(url))
print(test_plot)
test_plot_2 = ggplot(mtcars, aes('mpg', 'hp', color = 'factor(cyl)')) +\
geom_point() +\
scale_color_manual(values = coolors(url2))
print(test_plot_2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment