Last active
April 1, 2025 09:27
-
-
Save andrewmoles2/67fbd05bae17499f77a5682d5cffc40f to your computer and use it in GitHub Desktop.
Coolors function in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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